- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
I am writing a program with a series of lines at the top to manually enter various macros. Based on what macros are entered, I want to be able to run different lines of code and am not sure if this is possible in sas. high level overiew of what I want:
%let var1 = 123;
%let var2 = 'string';
/* %let var3 = 567; */
/* %let var5 = 999; */
if var3 is not null then
**proc sql code here**
else if var5 is not null then
**different proc sql code here**
else if var1 is not null then
**different proc sql code again**
end;
Is this possible in any way in sas? The user would be able to comment out the variables not in use, and it would run different querys depending on which variables were in use. Thanks!
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You can do this with macro statements. If you have SAS 9.4 TS1M5 or later
%if &var3^= %then %do;
**proc sql code here**
%end;
%else %if &var5^= %then %do;
**different proc sql code here**
%end;
If you are using earlier versions of SAS, you would have to include the above code in a macro.
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
"isn't working for me"
This gives us no information on how to move forward or help you. (Also, my code did not require %symexist, so I know you are not using my code)
Show us your code. Show us the LOG (all of the log, not just the ERROR messages)
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@mancel3 wrote:
The ^= syntax isnt working for me for some reason, and when I try to use %symexist(var1) it is returning true seemingly no matter what I do (if i comment out or delete the %let definition it still runs the code using that variable somehow. I haven have a delete all work statement at the top and it continues to do that) Any ideas?
%symexist will return "true" if the macro variable was created anytime during the SAS session ifthe variable was made as global macro variable such as the %let statements you show.
Show the entire syntax and notes from the log. There wasn't any indications that %symexist was relevant to the problem you discuss.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
%symexist will return "true" if the macro variable was created anytime during the SAS
and hasn't been %SYMDEL eted. Just to clarify for the OP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
> If you are using earlier versions of SAS, you would have to include the above code in a macro.
If you use an older version of SAS, here's another way that works in open code:
%sysfunc(ifc( &var3^=, %str( **proc sql code here** )
, %sysfunc(ifc( &var5^=, %str( **different proc sql code here** )
, )) ))