BookmarkSubscribeRSS Feed
weizhongma
Calcite | Level 5

Hi,

I have a dataset which contains one varible name with value of

NAME

AMORTIZED_INCOME__REV_

BONDS_BAL_

BONDS_REV_

CASA_BAL_

CASA_REV_

CASH_REV_

CASH_SECURED__BAL_

CASH_SECURED__REV_

CA_BAL_

How could I create a macro parameter varlist from above dataset the same as I did manually as below?

%LET varlist = %STR(

AMORTIZED_INCOME__REV_

BONDS_BAL_

BONDS_REV_

CASA_BAL_

CASA_REV_

CASH_REV_

CASH_SECURED__BAL_

CASH_SECURED__REV_

CA_BAL_) ;

Thanks for your help!

3 REPLIES 3
AncaTilea
Pyrite | Level 9

HI.

One way would be to use PROC SQL and SELECT INTO:

Something like this,

PROC SQL;

     SELECT NAME SEPARATED BY "  "

     INTO: NAME_LIST

FROM WORK.YOURDATA;

QUIT;

%PUT &NAME_LIST;

Anca.

weizhongma
Calcite | Level 5

Thanks Anca. But I got error message.

 

83 PROC SQL;

84 SELECT NAME

85 SEPARATED BY " "

--------- --

22 202

ERROR 22-322: Syntax error, expecting one of the following: a quoted string, !, !!, &, (, *, **, +, ',', -, '.', /, <, <=, <>,

=, >, >=, ?, AND, AS, BETWEEN, CONTAINS, EQ, EQT, FORMAT, FROM, GE, GET, GT, GTT, IN, INFORMAT, INTO, IS, LABEL,

LE, LEN, LENGTH, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, TRANSCODE, ^, ^=, |, ||, ~, ~=.

ERROR 202-322: The option or parameter is not recognized and will be ignored.

86 INTO: NAME_LIST

87 FROM xtest;

88 QUIT;

AncaTilea
Pyrite | Level 9

Yes, I made a mistake. Need to switch the into: and separated

You need select name into: name_list separated by ' '

From dataset;

Quit;

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!

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
  • 3 replies
  • 559 views
  • 0 likes
  • 2 in conversation