I've seen such effects on Santana, Robert Fripp and Steve Hackett. They produce a clean sustained sound and I don't know how to create it.
I know both Steve Hackett and Robert Fripp. I have interviewed them for articles I published in guitar magazines.
You are asking about an unusual effect that requires special equipment.
To get the sounds you described, early in their careers, Steve Hacket and Robert Fripp used the hand-held electro-magnetic bowing device called the EBow. Later on they used the Fernandes Sustainer installed in their guitars.
The Fernandes Sustainer is not really a pickup at all. It sits in a pickup cavity on the guitar, but it is a device that creates an alternating magnetic field that causes the strings to vibrate continuously as if it were being bowed by a violin bow. It can be used to create completely clean "infinite sustain" sounds, including chords, that are very different in character than what you get with a compressor pedal or with distortion or amp feedback. As long as you hold a note or chord, it never dies out or decays (as long as the batteries are working).
Today, both Hackett and Fripp will only perform with electric guitars with a Fernandes Sustainer installed. Furthermore their guitars have Floyd Rose-type tremolo bridges and not a hard-tail bridge.
Here is a link to Steve Hackett's own description of his guitar collection. The guitars he performs with today all have a Fernandes Sustainer.
Four years ago an entirely new system came on the market: the Moog Guitar. It is much more sophisticated in its ability to create clean sustaining sounds than either the EBow or the Fernandes Sustainer. Check the link for demo videos and recordings from Moog.
You can buy a relatively inexpensive Fernandes guitar with a Sustainer already installed, or you can purchase a Sustainer kit and have it retrofitted to an existing guitar. However, you will need to route out the body to make room for the extra components and batteries that the Sustainer system requires.
Neal Schon, Steve Vai, and The Edge are also Fernandes Sustainer endorsers.
One easy way: Use a sustain effect processor (Glossary of Guitar Effects). A sustain effect just saves the highest volume you played and raises the volume gradually as the tone from the guitar decays, thus effectively sustaining the volume at an equal level or at least a slowly decaying level in the dry channel.
First off we should understand that the nature of a plucked string is to decay exponentially.
There fore sustain on a guitar string is literally impossible without some sort of electronic enhancement.
Before I suggest any of a number of ways to create sustain, let's examine the contributing factors that allow some guitars (electric or non-electric) to appear to take longer to decay (appear to sustain longer).
1) Bolt on neck vs. set neck. Given 2 guitar bodies of the same design but one with a bolt on neck and the other with a set neck, the set neck will have a longer period of decay. This is because of the ability of a set neck to transmit sound waves better than a bolt on neck.
2) Hard tail bridge vs. tremolo bridge. Given 2 Fender stratocasters one with a the standard Fender tremolo bridge and the other with a hard tail bridge, the hard tail bridge will have a longer period of decay for the same reason as above.
3) The more mass at the headstock is another known contributing factor to create a longer decay.
4) The type of wood used in the guitar body construction is another factor. Hard woods will allow for a longer decay time than softer woods, e.g. Mahogany vs. basswood. This is because sound waves will travel faster as the density of wood increases which allows for better wave transmission. NOTE: most electric guitars may use many types of wood in their construction. Consider a Les Paul with a mahogany body, and a maple top, and an ebony fingerboard.
5) Heavier gauge strings will decay slower than light gauge strings as mass plays important role on wave transmission as well.
6) The nut and bridge material is also a factor. Again the density of the materials is significant. Consider the better wave transmission of graphite saddles vs. nickle.
In summary, the assorted materials that compose the guitar build are the most significant factors in creating longer decay times. One should consider everything from the string itself vibrating and transmitting through the nut and bridge to the neck and body.
Generally speaking a PRS guitar like the one Carlos Santana uses is optimized for his long 'sustained' notes, but that's only half the story, you should also see what pedals and tube amp he is using too.
Beyond the acoustic factors listed above, we should now examine the pick ups and the amplifier. There are a zillion pick ups out there, both single and dual coil (aka humbuckers) pick ups will vary on how the sound is transmitted to the amp and this will have an apparent influence on the decay time. The settings on the amp and the amp build may have an influence as well. Foot pedals aimed at increasing gain and compression are factors too. Consider SRV playing a strat through a tube screamer then into a vintage Fender Super Reverb with optimal NOS tubes, and a mix of AlNiCo and Ceramic speaker magnets. Plenty of sustain.
Let's not confuse sustain with tone, often pros will trade off one for the other as they journey their 'tone quest'.
Aside from using a "sustain effect processor" one could use any of the following to create sustain:
a) Ebow (http://en.wikipedia.org/wiki/EBow)
b) Old school controlled amp sustained feedback e.g.
c) Use a real bow on a guitar with violin strings and an arched bridge.
d) Post production using a DAW. Record your piece, copy and splice the waves on and on together.
e) Loop the sound in an effects box.
Here's a website that discusses real vs fake sustain: http://www.sustainiac.com/aboutsus.htm
There's lots of good stuff above, but that isn't all of it. Yes, many big names use the Sustainer and equivalent, and while I don't own a guitar like that, I heartily endorse the idea, but Carlos, Steve and Robert built their reputation well before it existed.
There are two things that happen when you turn up the amp. First, you get "natural compression" and the second is feedback. If the sound off the amp feeds into the guitar, you as the guitarist are no longer starting the sound but controlling it. If you're not feeding back, you still get the compression effect. There's also stomp boxes that give you that, and there exists a question to explain them.
Adding to the fantastic answers so far
The Acoustic Synthesizer: As a fairly new development, Paul Vo(the inventer of the Moog synthesiser) has been working on an addon for acoustic guitars which works like a sustainer, and can be used to manipulate the waveforms produced by the guitar. It sounds pretty trippy! here's their kickstarter
True Temprament: There's another technology that I don't think's been mentioned. True Temprament frets are a company that will re-fret your instrument so that it's more accurately in tune Intonation-wise right down to the last hz. This allows the notes to be more resonant with each other and thus, increase sustain :)
On Robert Fripp: Adding to what Wheat was saying about Robert Fripp, I unfortunately do not know him :(, but if you have Spotify there's a massive collection of interviews and after-show questions that he's done where he will occasionally talk about the equipment he uses, and this website lists all the gear, however further investigation is needed into what does what!
Santana/PRS: As for Santana, I know that PRS guitars (as used by Carlos Santana) have an extremely good reputation for having a resonant, rich, sustained sound. One of my favourite bands Opeth have been using PRSes for years, here are some examples.
Using/Abusing feedback/harmonics: There's a trick that Joe Satriani and Gary Moore have both used in order to get a sustained harmonic from their guitar, though slightly different. Gary moore setup his amp sound such that a certain note created a resonant frequency with the sound of the amp so that once he'd held the note, the feedback would sustain it enough that it didn't deafen, but also didn't fade. Those of you that know Gary Moore, know the note I mean!
Joe Satriani uses a similar trick. He lets the feedback create a note with his guitar, and then will move around the room until he finds another harmonic which resonates with the frequency, and this causes the note to change, while still sustaining.
The two linked videos on their names will make this much clearer!
Hope that helps add something :)
One way to give the illusion of a sustained note is to repick the note at a time where the pick attack will be disguised by something else going on in the music such as a snare hit or chord strum. Just make sure you don't pick so hard that you get twang or so the note comes back noticeably louser than it was before.
"u" out the nut and bridge string rests, as most are "V" shaped" use graphite (pencil lead powder) as well. use proper guaged strings for your guitar. (no they are not" one size fits all." use vibrato, as violinists do.
Just a few things not mentioned above.
" ah, careful with that there file Elroy !"