I am trying to write a macro to concatenate all values of a row. But its not working. can some one point out? Without the macro its working fine.
%macro dummy(var=);
proc sql;
create table values as select distinct(&var.) as vals from td;
run;
data values1;
length new_val $100.;
%do %until(eof);
set values end=eof;
new_val=catx("",new_val,vals);
%end;
run;
proc print data=values1;
run;
%mend;
%dummy(var=job);
When you say all values of a row do you mean the values in a row or column?
If a column, look at PROC SQL documentation on calculating macro variables.
If a row, try CATX(', ', of _all_);
Yes, macro language doesn't understand DATA step variables such as eof.
You seem to understand the right tools, why not use them:
proc sql;
select strip(var) into : vals separated by ',';
Or possible (but different):
select distinct strip(var) into : vals separated by ',';
If you really want this as a DATA step variable (although it is difficult to envision why), you could use:
data test;
longvar = "&vals";
run;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.