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

i have a data set like

data test;

input x y z;

..........

run;

i want a macro variable like x|y|z (concatenating the variable names)

is it possible in sas by proc sql or anyhow?

1 ACCEPTED SOLUTION

Accepted Solutions
Loko
Barite | Level 11

Hello,

with proc sql:

data test;
x=1;y=2;z=3;
run;

proc sql noprint;
select name into :allvars separated by '|' from sashelp.vcolumn
where libname='WORK' and memname='TEST';
quit;

View solution in original post

3 REPLIES 3
Loko
Barite | Level 11

Hello,

with proc sql:

data test;
x=1;y=2;z=3;
run;

proc sql noprint;
select name into :allvars separated by '|' from sashelp.vcolumn
where libname='WORK' and memname='TEST';
quit;

ChrisHemedinger
Community Manager

Do you want to concatenate the values of the variables into a new field?  Or create a SAS macro variable with the variable names?

If the latter, try something like this:

proc sql noprint;
select name into:MyVars separated by ' '
 
from sashelp.vcolumn
 
where libname="WORK" and memname="TEST";
quit;

%put &myvars;
 

If the former, then you can use one of the CAT functions (such as CATX) to create a new value in your DATA step:

newVal = CATX(' ',x,y,z);

That's not a macro var though.  If you need the macro variable you'll need to decide which particular record you want to represent, calculate the value, and you can use CALL SYMPUT to stuff it into a macro variable for use later in your program.

Chris

Check out SAS Innovate on-demand content! Watch the main stage sessions, keynotes, and over 20 technical breakout sessions!
Aman4SAS
Obsidian | Level 7

Thanks a lot.

is there any document related to it. Please share.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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