BookmarkSubscribeRSS Feed
BrahmanandaRao
Lapis Lazuli | Level 10
data quots;
x='(A,B,C,D,E)';
z=quote(x);
run;

hi guys

I want give quotes for list of letters

desired output

z=('A','B','C','D','E')

3 REPLIES 3
Kurt_Bremser
Super User

The function can only put quotes around the whole argument (read the documentation).

To put quotes around each comma-separated substring within the brackets, you need a DO loop with SCAN and rebuild the string in a new variable.

 

But there are two important questions: how is the string originally built, and what do you intend to do with it later?

Hao_Luo
SAS Employee

1. Remove the brakets outside;

2. Subtitute " , " as " ',' " ;

3. Concatenate brakets, single quotes and string in step 2;

data quots;
  x='(A,B,C,D,E)';
  y1=substr(x,2,length(x)-2);
  y2=tranwrd(y1,",","','");
  z="('"||trim(y2)||"')";
run;
Ksharp
Super User
data quots;
length x $ 40;
x='(A,B,C,D,E)';
z=prxchange("s/(\w+)/'\1'/",-1,x);
run;
proc print;run;

Ksharp_0-1678798726880.png

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 722 views
  • 1 like
  • 4 in conversation