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

 

Hi SAS Experts,


I have a data with name and strings, I want to add all the strings(col1,col2,etc..) into one column. The number of strings are not fixed they may be more or less sometimes. I can do this with catx but do not know how to achieve this with array. Below is my data set.  Please Guide.


data a;
input name$ col1$ col2$ col3$ col4$;
DATALINES;
Harry abc dcd vgd bvd
peter cvc fgf ghg ghh
John fgg ftg uty gfdg
sheyala fgf jty fhf fgr
;
run;


here is my code:

 

data test;
length result $50;
set a;
result=Compress(catx(';',of col1-col4),'0D0A'x);
run;

 

But the number of strings are not fixed. 

 

Thanks & Regards,

Sanjay

1 ACCEPTED SOLUTION

Accepted Solutions
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Are they all called colX if so you don't need an array:

result=catx(',',of col:);

Note the colon after the col prefix.

If they are not all called that then:

array tmp{*} col1 abc def;
result=catx(',',of tmp:);

View solution in original post

5 REPLIES 5
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Are they all called colX if so you don't need an array:

result=catx(',',of col:);

Note the colon after the col prefix.

If they are not all called that then:

array tmp{*} col1 abc def;
result=catx(',',of tmp:);
sanjay1
Obsidian | Level 7

Hi RW9,

 Can you elaborate how to use this with array.

ballardw
Super User

@sanjay1 wrote:

Hi RW9,

 Can you elaborate how to use this with array.


Use "of arrayname(*)" where your are currently using "of col1-col4". BUT you must define the array beforehand.

Reeza
Super User
If you need a solution like this, it's clearly homework so review your course notes or the documentation on how to reference "variable lists". The answer is on this page:
http://support.sas.com/documentation/cdl/en/lrcon/69852/HTML/default/viewer.htm#p0wphcpsfgx6o7n1sjtq...

BTW the answer on SO is incorrect. It does work, but if that's the homework question it's highly likely that's not the correct answer.

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
  • 5 replies
  • 9273 views
  • 1 like
  • 5 in conversation