BookmarkSubscribeRSS Feed
scb
Obsidian | Level 7 scb
Obsidian | Level 7

With the below program, i can only get 'book' for the macro variable.

 

May I know how to get macro variable 'orderedvars' that is 'book,car,ship,ball'? Anyone can help, thanks.

 

data sample;
input var1 $ var2 $ var3 $ var4 $;
cards;
book car ship ball
;
run;

 

proc sql noprint;
select distinct *
into : orderedvars separated by ','
from sample;
quit;

 

%put &orderedvars;

4 REPLIES 4
PaigeMiller
Diamond | Level 26
data _null_;
    call symputx('ordervars','book,car,ship,ball');
run;

OR

 

Transpose your data set sample and work from there.

 

OR

 

Read the four words into a single column in your data step.

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26
data sample;
  input var1 $ var2 $ var3 $ var4 $;
  call symputx('orderedvars',catx(',',of var:));
cards;
book car ship ball
;
run;

%put &orderedvars;

Thats likely the easiest way, into takes a column of observations not an array of variables.

FreelanceReinh
Jade | Level 19

PROC SQL could use the CATX function as well, except for the abbreviated variable list (which may be irrelevant anyway because your real variables are named differently):

proc sql noprint;
select catx(',', var1, var2, var3, var4)
into : orderedvars
from sample;
quit;
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, I was avoiding that as you can't use arrays of variables in sql, so:

select catx(',',of var:)

Thats why I went with the datastep, just easier.  SQL is only really columns of data, not arrays of variables. 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 580 views
  • 0 likes
  • 4 in conversation