BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
leannemcn13
Calcite | Level 5

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)

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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.

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

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.

 

leannemcn13
Calcite | Level 5

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. 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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