Below is my input
data have;
input col1 $4.;
cards;
abcd
efgh
ijkl
mnop
qrst
;
run;
Need output as follows
'abcd',
'efgh',
'ijkl',
'mnop',
'qrst'
Is this a possibility in SAS?
data foo;
input col1 $;
cards;
abcd
efgh
ijkl
mnop
qrst
;
run;
proc transpose data=foo out=bar(drop=_:); var col1; run;
filename tmp temp;
data _null_;
set bar;
file tmp dlm=',' dsd;
put (col:) ($~);
run;
"abcd","efgh","ijkl","mnop","qrst"
*or;
data bar;
set foo;
col1=quote(strip(col1));
run;
*or;
data foo;
format col1 $quote.;
input col1 $;
cards;
abcd
efgh
ijkl
mnop
qrst
;
run;
proc print data=foo; run;
Is it the quoted part or each result on a separate line that you'd like?
And yes it's possible...
data _null_;
set sashelp.class;
file "C:\temp\test.csv" dlm=',' dsd;
put
name $~
sex $~
height $~
weight $~
age $~
;
run;
I need it for every observation. I only have one variable in the data set and it has to be in the ' ', format.
how about this one?
data have;
input col1 $4.;
cards;
abcd
efgh
ijkl
mnop
qrst
;
run;
data want;
set have;
length n $8;
n='*'||col1||'*';
nn=translate(n,"'","*");
run;
proc print;run;
Obs col1 n nn
1 abcd *abcd* 'abcd'
2 efgh *efgh* 'efgh'
3 ijkl *ijkl* 'ijkl'
4 mnop *mnop* 'mnop'
5 qrst *qrst* 'qrst'
Linlin
Thanks Linlin. It worked but I have to add , to the code.
data have;
input col1 $4.;
cards;
abcd
efgh
ijkl
mnop
qrst
;
run;
data want;
set have;
length n $8;
n='*'||col1||'*'||',';
nn=translate(n,"'","*");
run;
proc print;run;
data foo;
input col1 $;
cards;
abcd
efgh
ijkl
mnop
qrst
;
run;
proc transpose data=foo out=bar(drop=_:); var col1; run;
filename tmp temp;
data _null_;
set bar;
file tmp dlm=',' dsd;
put (col:) ($~);
run;
"abcd","efgh","ijkl","mnop","qrst"
*or;
data bar;
set foo;
col1=quote(strip(col1));
run;
*or;
data foo;
format col1 $quote.;
input col1 $;
cards;
abcd
efgh
ijkl
mnop
qrst
;
run;
proc print data=foo; run;
I thought the OP asked for single quote.
hi ,,, another idea ...
data want;
length col2 col3 $6;
set have;
col2 = catq('2a',col1);
col3 = catq('1a',col1);
run;
or, no LENGTH statement needed ...
data want;
set have;
col2 = put(col1,quote.);
col3 = translate(col2,"'",'"');
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.