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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.