SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Ronein
Meteorite | Level 14

Hello

Lets say that I  want to find all data sets in library R_R that start with name "ALERTSNEG_"

For example: ALERTSNEG_202401 , ALERTSNEG_202402, ALERTSNEG_202403 and so on

Lets say that I want to create a macro var that concatenated these data sets names.

My question:

what is the target of writing the code : %let memlist=_null_;

The code can also run without it.

Can anyone explain what is the benefit of this code?

 

 

proc sql noprint ;
%let memlist=_null_;
select catx('.',libname,memname)
    into :memlist separated by ' '
from dictionary.members 
where libname='R_R'
      and (memname like 'ALERTSNEG_%')
  ;
quit;
%put &memlist;
1 ACCEPTED SOLUTION

Accepted Solutions
4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Probably just to ensure that memlist does not contain anything from the previous run of the code. It works perfectly fine without it though. 

Kurt_Bremser
Super User

If there's no dataset satisfying the WHERE requirement, PROC SQL would not create the macro variable, causing ERRORs later on when you use it. The %LET avoids this.

Ronein
Meteorite | Level 14

Is it equivalent to write 

%let memlist=_null_;

before the proc sql?

%let memlist=_null_;
proc sql noprint ;
select catx('.',libname,memname)
    into :memlist separated by ' '
from dictionary.members 
where libname='R_R'
      and (memname like 'ALERTSNEG_%')
  ;
quit;
%put &memlist;

 

Kurt_Bremser
Super User
Answer these two questions:
- When are macro statements executed/resolved?
- When does the SQL procedure execute statements, interactively when encountered, or all at once when QUIT; is parsed?

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!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1029 views
  • 4 likes
  • 3 in conversation