I have a piece of code that I want to use, possibly inside and outside of data steps. In order to use "DOSUBL" I need to check whether I'm inside a data step or not. I know it doesn't sound great, but just bare with me.
I've tried SYSLAST etc but it doesn't work.
data test1; set test; %com(blah blah blah); %macro com /parmbuff; ***WOULD LIKE TO INSERT CODE HERE TO CHECK IF I'M INSIDE DATASTEP**** rc = %sysfunc(dosubl( *extra code* )); %mend com; run;
I've tried changing it to macro code such as:
data test1; set test; %com(blah blah blah); %macro com /parmbuff; %let rc = %sysfunc(dosubl( *extra code* )); %mend com; run;
But constantly got the errors:
NOTE: One or more missing close parentheses have been supplied for the %DOSUBL function.
ERROR: Expected close parenthesis after macro function invocation not found.
& yes i did have the same amount of open brackets as i did closed. It should be noted that inside the *extra code section* I have data steps, let statements, macro do's etc.
Wondering if anyone knows of any functions that would help me do this. I was thinking if there was something to check if last data step was closed or something. I'm a bit unsure what I'm looking for, so open to suggestions.
(Please don't ask me why its confusing and will sound silly to anyone not working on it)
Use the automatic macro variable SYSPROCNAME.
%macro test;
%if &sysprocname=DATASTEP %then %put Running in Data step ;
%else %put NOT in data step;
%mend test;
data a;
set sashelp.class ;
%test;
run;
proc sql ;
%test;
quit;
%test;
PS. Your sample code is garbled as it has the macro definition AFTER the macro call. On top of that it has the macro definition in the middle of a data step.
Use the automatic macro variable SYSPROCNAME.
%macro test;
%if &sysprocname=DATASTEP %then %put Running in Data step ;
%else %put NOT in data step;
%mend test;
data a;
set sashelp.class ;
%test;
run;
proc sql ;
%test;
quit;
%test;
PS. Your sample code is garbled as it has the macro definition AFTER the macro call. On top of that it has the macro definition in the middle of a data step.
Yes, this is not my actual code- that was private, hence the "blah blah blah". I just wanted to give you a quick example.
Either way that has worked, thank you so much! I can now finish for Christmas break Happy as Larry.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.