BookmarkSubscribeRSS Feed
pri2
Calcite | Level 5

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);

3 REPLIES 3
Reeza
Super User

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_); 

pri2
Calcite | Level 5
I meant all values of the column..it is not able to get the value of Eof
Astounding
PROC Star

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;

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 698 views
  • 0 likes
  • 3 in conversation