Desktop productivity for business analysts and programmers

Concat Variable names

Accepted Solution Solved
Reply
Super Contributor
Posts: 265
Accepted Solution

Concat Variable names

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?


Accepted Solutions
Solution
‎09-12-2014 08:23 AM
Super Contributor
Posts: 305

Re: Concat Variable names

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


All Replies
Solution
‎09-12-2014 08:23 AM
Super Contributor
Posts: 305

Re: Concat Variable names

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;

Community Manager
Posts: 2,696

Re: Concat Variable names

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

Super Contributor
Posts: 265

Re: Concat Variable names

Thanks a lot.

is there any document related to it. Please share.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 618 views
  • 3 likes
  • 3 in conversation