Date: Wed, 14 May 2003 09:47:27 -0700
Reply-To: Prasad S Ravi <prasad.s.ravi@HOUSEHOLD.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Prasad S Ravi <prasad.s.ravi@HOUSEHOLD.COM>
Subject: Re: suppressing quotes in export; breaking apart variables
Content-type: text/plain; charset=us-ascii
Simian:
For your qn:
Is there an easier way to create new variables out of existing ones
based on an internal delimiter in the data step without this
import/export madness? For example, creating out of a var1 value of
'alpaca:llama' new variables, var1a = 'alpaca' and var1b = 'llama'?
Did you try using SCAN function?, along with concatenating the single
quotes.
var1a="'"||scan(var1,1,':')||"'";
var1b="'"||scan(var1,2,':')||"'";
Is this what you want?.
Prasad Ravi
simian
<headmind@MINDHEAD.CO To: SAS-L@LISTSERV.UGA.EDU
M> cc:
Sent by: "SAS(r) Subject: suppressing quotes in export; breaking apart variables
Discussion"
<SAS-L@LISTSERV.UGA.E
DU>
05/14/2003 12:46 AM
Please respond to
simian
Hello all,
I have a question about a kluge, and maybe some of you know a solution
that will enable me to avoid the kluge entirely.
1) I'm trying to export a table as a colon-delimited file. SAS
defaults to putting double quotes around a value that contains a colon
already. How do I suppress this behavior? Here's my current script:
data _null_;
set EE.EE end=EFIEOD;
file 'd:\ee_out.txt'
delimiter=':' DSD DROPOVER lrecl=32767;
format var1 $500. ;
format var2 best12. ;
format var3 $40. ;
if _n_ = 1 then do;
put 'var2' ':'
'var1a' ':'
'var1b'
; end;
do;
EFIOUT + 1;
put var2 @;
put var1 $;
; end;
run;
2) The point of doing the above is that I want to use the colons
embedded in the values of var1 to break out var1 into two separate
fields, var1a and var1b. I had planned to do this by exporting the
file as above, and then re-importing it as a colon-delimited file, but
the double quotes foiled me.
Is there an easier way to create new variables out of existing ones
based on an internal delimiter in the data step without this
import/export madness? For example, creating out of a var1 value of
'alpaca:llama' new variables, var1a = 'alpaca' and var1b = 'llama'?
3) on a related note, how I got to 'alpaca:llama' in the first place
was by having something like
"<junk>alpaca<morejunk>llama<evenmorejunk>' in a long character
variable. I knew what the <junk> tended to look like so I killed it
like so:
var1 = tranwrd(compbl(trim(var1)),"<junk>","");
What I'd rather do is simply replace anything in < >'s with a
delimiter (without knowing whether the contents of the < > are
identically "junk" or not), and then delimit my file by those new
delimiters.
Any thoughts?
Thank you!
VJ
headmind@mindhead.com