BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
SAS_inquisitive
Lapis Lazuli | Level 10

What is the difference between specifying CALL EXECUTE at first iteration and not specifying any interation at all?

data test;
	call execute('proc print data=sashelp.class;run;');
run;

data test;
	if _n_=1 then
		call execute('proc print data=sashelp.class;run;');
run;
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

I was referring to "The" documentation.  https://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p1blnvlvci...

 

Spoiler

Details

If argument resolves to a macro invocation, the macro executes immediately and DATA step execution pauses while the macro executes. If argument resolves to a SAS statement or if execution of the macro generates SAS statements, the statement(s) execute after the end of the DATA step that contains the CALL EXECUTE routine. CALL EXECUTE is fully documented in SAS Macro Language: Reference.

But I realize that %NRSTR is not mentioned.

 

I believe Roland's explanation of the issue is adequate.  Here is the link to the SAS-L tread where he learnt how CALL EXECUTE works. https://listserv.uga.edu/cgi-bin/wa?A2=ind1210c&L=SAS-L&D=0&X=83E8E1025408227B5F&Y=datanull%40gmail....

View solution in original post

10 REPLIES 10
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Not a lot.  If you have a data step, with no set clause like that, an empty observation is created, hence because there is one observation the call execute gets executed exactly once.  In your second example, exactly the same thing happens, one blank observation is create and it has _n_=1, so call execute happens once also. 

data_null__
Jade | Level 19

Notice that both data steps produce the same data set output.

 

NOTE: The data set WORK.TEST has 1 observations and 0 variables.

I've yet to find a use for that. 🙂  Although a 0 obs 0 vars can be useful.

 

 

Probably a case for 

data _null_;

makes you look you know what you're doing.

SAS_inquisitive
Lapis Lazuli | Level 10

 @RW9 @data_null__. Thank you. The other thing that baffles me when the argument of CALL EXECUTE is some macro.  CALL EXECUTE sends its argument to macro processor for execution. Doesn't macro code go to macro processor without the need of CALL EXECUTE?

data_null__
Jade | Level 19

Macro code or a macro call is executed immediately by CALL EXECUTE any code emitted by calling a macro or code written directly by CALL EXECUTE is "stacked" for execution after the data step that is doing the CALL EXECUTEing is done.  This is subtle difference between calling a macro the "regular way" vs EXECUTE and not well understood by most users.

 

See the bit about %NRSTR in the documentation.

SAS_inquisitive
Lapis Lazuli | Level 10

@data_null__. Thank you. 

 

I found this one (%nrstr in call excute).

 

http://www.datasavantconsulting.com/roland/call_exec.html

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Do note, I generally avoid using the two together, there is really no need, they both do a similar job at the end of the day, so its simpler to choose one or the other approach.  That being said, 90% of the time you don't need to use either, Base SAS can do most things.

SAS_inquisitive
Lapis Lazuli | Level 10

@RW9 You wrote "Do note, I generally avoid using the two together".

 

two means CALL EXECUTE and Macro?

 

I really want to expand my sas skills horizon that's why I want to learn useful new technique if there is. I have found people using CALL EXECUTE in their program.I have not used it in my program yet. But curious if I can use in my case. 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Yes, only use one method to generate code, either macro or call execute.  They both have their benefits and drawbacks, but ultimately do a similar thing.

Its really down to what the code is to be used for.  If its a one off program, then use Base SAS which can basically do 99% of things, and if you really need to repeat code, use call execute.  If you need reusable code, then macro is probably better.

data_null__
Jade | Level 19

I was referring to "The" documentation.  https://support.sas.com/documentation/cdl/en/lefunctionsref/67960/HTML/default/viewer.htm#p1blnvlvci...

 

Spoiler

Details

If argument resolves to a macro invocation, the macro executes immediately and DATA step execution pauses while the macro executes. If argument resolves to a SAS statement or if execution of the macro generates SAS statements, the statement(s) execute after the end of the DATA step that contains the CALL EXECUTE routine. CALL EXECUTE is fully documented in SAS Macro Language: Reference.

But I realize that %NRSTR is not mentioned.

 

I believe Roland's explanation of the issue is adequate.  Here is the link to the SAS-L tread where he learnt how CALL EXECUTE works. https://listserv.uga.edu/cgi-bin/wa?A2=ind1210c&L=SAS-L&D=0&X=83E8E1025408227B5F&Y=datanull%40gmail....

SAS_inquisitive
Lapis Lazuli | Level 10

@data_null__. Thank you.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 10 replies
  • 1170 views
  • 4 likes
  • 3 in conversation