BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hima
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
FriedEgg
SAS Employee

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;

View solution in original post

7 REPLIES 7
Reeza
Super User

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;

Hima
Obsidian | Level 7

I need it for every observation. I only have one variable in the data set and it has to be in the ' ', format.

Linlin
Lapis Lazuli | Level 10

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

Hima
Obsidian | Level 7

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;

FriedEgg
SAS Employee

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;

Linlin
Lapis Lazuli | Level 10

I thought the OP asked for single quote.

MikeZdeb
Rhodochrosite | Level 12

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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1784 views
  • 3 likes
  • 5 in conversation