BookmarkSubscribeRSS Feed
RichardAD
Quartz | Level 8

What would you expect this code to do?

data _null_;
  set sashelp.class(obs=4) end=end;
  call execute ('/*');
  call execute ('proc print data=sashelp.class;');
  call execute ('where name='||quote(trim(name))||';');
  call execute ('run;');
  call execute ('*/;');
run;

Would you expect the proc prints to occur?

5 REPLIES 5
Tom
Super User Tom
Super User

No idea. 

Why would you attempt to send block comments to CALL EXECUTE()?  And if you did why in multiple function calls?

 

Write the code to a file if the goal is to produce a human readable code file.  Then the block comments will work as expected when the file is sourced using %INCLUDE.

PaigeMiller
Diamond | Level 26

This code works to comment out the PROC PRINTs, but I don't think I can explain why this works while your original code doesn't.

 

data _null_;
  set sashelp.class(obs=4) end=end;
  call execute ('/%str(*)');
  call execute ('proc print data=sashelp.class;');
  call execute ('where name='||quote(trim(name))||';');
  call execute ('run;');
  call execute ('*/');
run;
--
Paige Miller
Tom
Super User Tom
Super User

Here is another one.

This works:

data _null_;
  call execute('proc print data=sashelp.class;var');
  call execute('name');
  call execute('sex');
  call execute(';run;');
run;

But if you send the exact same set of characters as one string it does not work since there is nothing between the variable names.

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

Breaking the statements into multiple pieces has an impact on how it is parsed by SAS.

 

yabwon
Onyx | Level 15

call execute's doc says: "Resolves the argument, and issues the resolved valuefor execution at the next step boundary."

 

so there is fair chance "something" is done with the text.

It looks a bit like all open comments are automatically "closed" at the end of the call, look at this:

data test;
  set sashelp.class(obs=5);
run;

data _null_;
  set sashelp.class(obs=1) end=end;

  call execute ('proc print /* data=sashelp.class; */ /* data _null_; set sashelp.class;');
  call execute (';where name='||quote(trim(name))||';'); /* semicolon added at the beginning of the line*/
  call execute ('run;');
  call execute ('*/;');
run;

log says:

1    data test;
2      set sashelp.class(obs=5);
3    run;

NOTE: There were 5 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.TEST has 5 observations and 5 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


4
5    data _null_;
6      set sashelp.class(obs=1) end=end;
7
8      call execute ('proc print /* data=sashelp.class; */ /* data _null_; set sashelp.class;');
9      call execute (';where name='||quote(trim(name))||';');
10     call execute ('run;');
11     call execute ('*/;');
12   run;

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: CALL EXECUTE generated line.
1   + proc print
2   + ;where name="Alfred";
3   + run;

NOTE: There were 1 observations read from the data set WORK.TEST.
      WHERE name='Alfred';
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.01 seconds


4   + */;

Here is another example that something is happening "at the end of call"

data _null_;
  set sashelp.class(obs=1) end=end;
  call execute ('%nrstr(');
  call execute ('/*');
  call execute ('proc print data=sashelp.class;');
  call execute ('where name='||quote(trim(name))||';');
  call execute ('run;');
  call execute ('*/;');
  call execute (')');
run;

Log shows 2 errors:

1    data _null_;
2      set sashelp.class(obs=1) end=end;
3      call execute ('%nrstr(');
4      call execute ('/*');
5      call execute ('proc print data=sashelp.class;');
6      call execute ('where name='||quote(trim(name))||';');
7      call execute ('run;');
8      call execute ('*/;');
9      call execute (')');
10   run;

ERROR: Expected close parenthesis after macro function invocation not found.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: There were 1 observations read from the data set SASHELP.CLASS.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: CALL EXECUTE generated line.
2   + proc print data=sashelp.class;
3   + where name="Alfred";
4   + run;

NOTE: There were 1 observations read from the data set SASHELP.CLASS.
      WHERE name='Alfred';
NOTE: PROCEDURE PRINT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


5   + */;
NOTE: Line generated by the CALL EXECUTE routine.
6   + )
      -
      180

ERROR 180-322: Statement is not valid or it is used out of proper order.

All the best

Bart

 

P.S. Agree with @Tom 's suggestion to do it in one call:

 

something like:

data _null_;
  set sashelp.class(obs=1) end=end;
  call execute ( " "
             !! "/*"
             !! 'proc print data=sashelp.class;'
             !! 'where name='||quote(trim(name))||';'
             !! 'run;'
             !! '*/'
             );
run;

 such setup allows even for "cinditional" commenting out:

%let commentOut=1;
data _null_;
  set sashelp.class(obs=1) end=end;
  call execute ( " "
             !! ifc(symgetn('commentOut'), "/*", " ")
             !! 'proc print data=sashelp.class;'
             !! 'where name='||quote(trim(name))||';'
             !! 'run;'
             !! '*/'
             );
run;
_______________
Polish SAS Users Group: www.polsug.com and communities.sas.com/polsug

"SAS Packages: the way to share" at SGF2020 Proceedings (the latest version), GitHub Repository, and YouTube Video.
Hands-on-Workshop: "Share your code with SAS Packages"
"My First SAS Package: A How-To" at SGF2021 Proceedings

SAS Ballot Ideas: one: SPF in SAS, two, and three
SAS Documentation



Quentin
Super User

Interesting.  If you have Display Manager (PC SAS), you can submit code one statement at time, in some settings one token at a time.  And sometimes it's instructive.  This doesn't work with EG or I suspect Studio, because they're essentially doing batch submits and add wrapper code.

 

Forget CALL EXECUTE for a moment, if you code:

/*
proc print data=sashelp.class;
run ;
*/

And run the code one line at a time (so 4 code submissions), it will run the PROC PRINT step.  And the last */ will not create an un-closed * comment.

 

My log looks like:

1    /*

2    proc print data=sashelp.class;
3    run ;

NOTE: There were 19 observations read from the data set SASHELP.CLASS.

4    */

So even without CALL EXECUTE, if you submit a just a /* token, SAS is automatically closing it.  And if you submit just */, SAS is also automatically closing that * comment.

 

I don't know if there is a documented rule about SAS automatically closing a comment if you submit an un-closed comment.  But it seems to be part of the SAS language, not CALL EXECUTE.

 

The Boston Area SAS Users Group is hosting free webinars!
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 5 replies
  • 1065 views
  • 3 likes
  • 5 in conversation