BookmarkSubscribeRSS Feed
Arun_shSAS
Fluorite | Level 6

 

%let C=test;



Data a;

input x $;

cards;

LI 

GI 

H&C

;



Proc sql noprint;

select x into: test2 separated by "," from a;

quit;

 

I want macro variable test2 to be resolved as LI,GI,H&C

 

3 REPLIES 3
Astounding
PROC Star
There will likely be headaches down the road, but you should be able to use %SUPERQ. For example:

%put %superq(test2);
Patrick
Opal | Level 21

@Arun_shSAS 

Looks like a case for %SUPERQ() or SYMGET().

%let C=test;

data a;
  input x $;
  cards;
LI 
GI 
H&C
;

proc sql noprint;
  select x into :test2 separated by "," from a;
quit;

%put Option_1: %superq(test2);

data _null_;
  Option_2=symget("test2");
  put Option_2=;
run;
Kurt_Bremser
Super User

The first question that comes to mind is "what for"?

Macro variables are the worst place for keeping data, SAS provides datasets as storage for that.

 

And if you need reference data for, say, where conditions, it's always better to use a defined key of some kind and not free-form text, which is the worst you can use for such things.

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 989 views
  • 0 likes
  • 4 in conversation