Used to be that RAW, the sniper wasn't getting the sneak attack. Why? No good reason other than that "a legalistic reading of the rules said so." There are no end of huge threads on paizo.com going over in tortuous detail how vision and stealth and all that work in PF core, especially here and here, and the summary was "slavishly following the rules means things that make no sense." You never get sneak attack from stealth because "you can't stealth while attacking" and "it doesn't say you get sneak attack just because someone can't see you, as hidden isn't an official condition (tm)."
I would previously invoke GM privilege to implement RAI - as in Pathfinder they say clearly "the GM is the law over and above the written rules" - and make it so they get their sneak attack. Because it makes sense from a game world logic/sim point of view and you can rule that's more important than the RAW point of view. IMO the clear intent was to sneak-attack someone from Stealth. You know, "sneak," "attack," things that happen in the real world and every previous edition of D&D.
Can I Attack From Stealth?
Now, however, the Stealth rules have been errata'ed to specifically say "you can attack from stealth" which means that yes, you get the sneak attack. See the updated version on the PRD which says:
Breaking Stealth: When you start your turn using Stealth, you can leave cover or concealment and remain unobserved as long as you succeed at a Stealth check and end your turn in cover or concealment. Your Stealth immediately ends after you make an attack roll, whether or not the attack is successful (except when sniping as noted below).
Sniping: If you've already successfully used Stealth at least 10 feet from your target, you can make one ranged attack and then immediately use Stealth again. You take a –20 penalty on your Stealth check to maintain your obscured location.
So the RAW has been updated to match the RAI for whatever that's worth (apparently it's really meaningful to some, though all my rogues have been happily sneak attacking from Stealth since the year 2000...).
Does A Stealthed Attack Enable Sneak Attack?
Yes, if you're stealthed, your attacks are sneak attacks.
Jason Buhlman states the intent clearly on the Paizo forums:
For simplicities sake, it should be assumed that those making Perception checks get to do so at the most favorable point during the movement of a character using Stealth, to avoid making checks every time the condition changes. Technically, I think you would get a check whenever the conditions change, but that might make things overly complicated during play.
Creatures are denied their Dexterity bonus to AC "if they cannot react to a blow" (CR pg 179 under AC). It was our intent that if you are unaware of a threat, you cannot react to a blow. I think we probably should have spelled this out a wee bit clearer, but space in the Stealth description was extraordinarily tight and ever word was at a premium. That said, I think these changes clear up the situation immensely (compared to where they were.. which was nebulous at best).
They didn't bother changing the RAW because most people use common sense and play it that way. Stealthed = sneak, etc.
RAW + Pathfinder = Sad Panda
This is why, whether you like this or not, a pure RAW approach to Pathfinder is always going to be frustrating; the devs explicitly don't bother to clean up RAW when RAI and/or common sense is clear. It's not a priority of theirs and I for one am pretty happy about that - they spend their intellectual capital making new interesting fun content instead of crafting rules and just retreading the same content year after year like WotC did with 3.5 (Return to the Return to the 1e Module, anyone?).
Hiding behind a wall
If you have partial cover, you may use Stealth. If you have total cover (wall is taller than you, or floor-to-ceiling, or whatever), you don’t even need Stealth. So you may hide behind a wall.
Readying an attack
You may then ready an attack for when he enters a square next to you, since an Attack Action may be done as a Standard and you are allowed to ready those. Your DM may require that you specify which square; the rules leave it up to the DM how specific you have to be. In any event, if this readied action is triggered, however specific your DM requires it to be, you then attack the target.
Sneak Attack?
The most recent errata gives you Total Concealment until after you make an attack. So what does that give you? Well, it means he doesn’t know what square you’re in and takes a 50% miss chance even if he guesses the right square. Does that let you Sneak Attack?
No. It does not. Sneaking does not actually let you Sneak Attack.
Commentary on this errata seems to indicate that the point of the errata was to allow rogues to Sneak Attack while, ya know, sneaking, but that doesn’t actually seem borne out by the rules.
So the rules don’t actually give you a Sneak Attack, even though you are considered “hidden” for that first attack (the one you readied). If your DM is sane, he’ll allow sneaking to trigger Sneak Attacks, because it’s ridiculous that the rules don’t allow it. Paizo’s lead dev has even stated (if you go digging through the forums) that it’s supposed to work; why he doesn’t just fix the rules is anyone’s guess, but there it is. Ultimately, this is something you’ll have to ask your DM about.
Does this sound flawed...or brilliant?
Considering that it doesn’t work, quite flawed, but even if we assume it’s allowed to work, it’s still pretty poor damage most of the time. Rogues tend to have very little combat presence at mid-to-high levels if they can’t get full attacks with Two-Weapon Fighting to multiply their Sneak Attack damage. At low levels, it could be a useful trick.
Of course, with the various ways that Pathfinder has shafted rogues’ ability to Sneak Attack multiple times in a round, it may be the best you can hope for. Unfortunately, it’s not very good.
Best Answer
As @mxyzplk said, you will need to deny your opponents their Dexterity bonus to AC.
Here are some ways to do that at range (sorry about the length):
Force them to Balance
Opponents are flat-footed while Balancing unless they have 5 ranks in Balance in 3.5 (or just always, regardless of their Acrobatics skill in PF, if I recall). The Grease spell works well if you have a mage handy, marbles (from the Arms and Equipment Guide) are a cheap mundane alternative. This is a low-level tactic that fades in usefulness as more enemies start flying.
Obtain Invisibility
The standard Invisibility spell and the associated ring only work for one attack, Greater Invisibility is better. The easiest ways to get Greater Invisibility are usually asking a friendly mage, obtaining a wand (use your Use Magic Device skill!) or prestige/multiclassing into a class that offers it, like Assassin.
Hide
The Hide rules are odd, but they can get the job done. Forget that Sniping option, it's redundant due to this line:
So just do the impossible. Pump up your Hide skill and hide while attacking. You will most likely need to find some way to get a Hide in Plain Sight ability (depending on the version you use, you may also need a way to generate cover or concealment), in core, the Shadowdancer is probably the best. Outside of core, you have things like the Dark template (Tome of Magic) to do it more easily.
In any case, this is a powerful option if you are good at increasing your skill check modifiers. Particularly, this can work even against foes with True Seeing (which foils Invisibility). If you take the Darkstalker feat (Lords of Madness), it foils several common anti-hide special abilities too.
Blink
The Blink spell denies your opponents their Dexterity bonus to AC. This is useful because there is a handy ring that grants the spell, even if it comes with limitations.
Blinking works best when combined with the Pierce Magical Concealment feat from Complete Arcane, to negate your own miss chance.
Other: Specific Sneak Attack enforcing options
There are ways to deliver Sneak Attack damage outside normal limitations (the target needing to be flanked or denied Dexterity bonus). The most effective ones I know are:
These may be difficult to fit into a build, but they can be effective.
There are also things like the Arcane Trickster's Impromptu Sneak Attack, but that's a limited ability of an unimpressive class.
Other: Flank anywhere
The Clarion Commander tactical feat (Tome of Battle) has this option:
This unusual wording allows anyone to flank without the usual setup. Assuming no argument is made about it simply not being possible to take advantage of this "flanking" with a ranged weapon, it allows a Rogue to Sneak Attack from range without denying Dex.
So, if there's someone in your party who is likely to get in a melee attack in the first round of each combat (even if that is the Rogue) and that someone can be convinced to take this feat, the Rogue is set.
Do not recommend: Grapple
While it may be tempting to pair up with a big bruiser and have them grapple opponents while you pepper with ranged attacks, the strategy becomes awkward in practice. At low levels, you will not have the Improved Precise Shot feat, so shooting into a grapple will be a dangerous game. At higher levels, monsters with enormous grapple check modifiers and/or Freedom of Movement effects become rather too common for grappling to be a reliable strategy at all.