BookmarkSubscribeRSS Feed
Liliya95
Fluorite | Level 6

How I can trim the line until the symbol in the loop?

for example, " abc, defg, hj, kli "

I need to get "abc"  "defg" "hj" "kli"

2 REPLIES 2
ShiroAmada
Lapis Lazuli | Level 10

 

Use the following functions - COUNTC, SUM, SCAN

data sample;
 a="'abc','def','xyz'";
 count_commas=countc(a);
if count_commas>1 then do;
 count_commas=count_commas+1;
  do i=1 to count_commas;
  var=scan(a,",",i);
  output;
end;
end;
if count_commas=0 or count_commas=. then var=a; run;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

What do you mean by "I need to get..."?  This is where posting test data as a datastep and what you want out is so important.  We are now all guessing what you want to do!  From what you post, it seems that you want to replace , with " ", which would be:

want=tranwrd(have,',','" "');

Posting clear concise questions will get you clear concise answers.

sas-innovate-2024.png

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.

 

Register now!

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
  • 2 replies
  • 708 views
  • 1 like
  • 3 in conversation