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
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:);
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:);
Hi RW9,
Can you elaborate how to use this with array.
@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.
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: