BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
data_null__
Jade | Level 19

When I call the macro in the source below PROC SCAPROC stops recording and closes the SCA file.  I have a simple test step that uses DOSUBL but does not cause the recording to stop.  If you are interested in this topic, please run the program below first with %if 0 %then %do;

save a copy of SCA file then with %if 1 %then %do;

and compare the two.  You should see that the recording stopped after calling M_EXPAND_VARLIST 

 

 

 

 

options ls=max mprint=1;
proc scaproc;
   record '.\dosubl-scaproc-bug-2.sca' expandmacros opentimes;
   run;

%macro
   m_expand_varlist /*Returns an expanded variable list and optionally creates an indexed data set of variable names*/
      (
         data  = _LAST_,            /*[R]Input data*/
         var   = _ALL_,             /*[R]Variable List expanded*/
         copy  = &var,              /*[O]Copy &VARS to the OUT= data set*/
         where = 1,                 /*[R]Where clause to subset OUT=, useful for selecting by a name suffix e.g. where=_name_ like '%_Status'*/
         expr  = nliteral(&name),   /*[R]An expression that can be used to modify the names in the expanded list*/
         keep  = ,                  /*[O]Keep data set option for DATA=*/
         drop  = ,                  /*[O]Drop data set option for DATA=*/
         rename= ,                  /*[O]Rename data set option for DATA=*/
         out   = work._deleteme_,   /*[O]Output data indexed by _NAME_ and _INDEX_*/
         name  = _NAME_,            /*[R]Name of the variable name variable in the output data set*/
         label = _LABEL_,           /*[R]Name of the variable label variable in the output data set*/
         index = _INDEX_,           /*[R]Name of the variable index variable in the output data set*/
         dlm   = ' '                /*[R]List delimiter*/
      );
   %local m i;
   %let i=&sysindex;
   %let m=&sysmacroname._&i;
   %do %while(%symexist(&m));
      %let i = %eval(&i + 1);
      %let m=&sysmacroname._&i;
      %end;
   %put NOTE: &=m is a unique symbol name;
   %local rc &m code1 code2 code3 code4 code5;
   %let code1 = %str(options notes=1; proc transpose name=&name label=&label data=&data(obs=0 keep=&keep drop=&drop rename=(&rename)) out=&out(where=(&where)); var &var; copy © run;);
   %let code2 = %str(data &out(index=(&index &name)); set &out; &index+1; run;);
   %let code3 = %str(proc sql noprint; select &expr into :&m separated by &dlm from &out; quit;);
   %if %superq(OUT) eq %str(work._deleteme_) %then %let code4=%str(proc delete data=work._deleteme_; run;);
   %let code5 = %str(options notes=1;run;quit;);
   %let rc=%qsysfunc(dosubl(&code1 &code2 &code3 &code4 &code5));
%unquote(&&&m)
   %mend m_expand_varlist;


data _null_;
   rc = dosubl('%trim(   proc contents data=sashelp.cars varnum; run;)');
   put rc=;
   run;

%if 0 %then %do;   /*Change 0 to 1 to see SCA file that ends after calling M_EXPAND_VARLIST*/
   %global classvars;
   %let classvars=%m_expand_varlist(data=sashelp.classfit,var=_CHARACTER_,out=expand);
   %put NOTE: &=classvars;
   proc print data=expand;
      run;
   %end;

%put _all_;



data shoes shoes2 shoes3;
   set sashelp.shoes;
   run;
proc contents varnum;
   run;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Interesting. 

 

I could not replicate on Display Manager interactive SAS (9.4M7) but could when I ran in batch mode.

 

As you showed, it looks like it's not a %sysfunc() problem, or a DOSUBL problem, but a %sysfunc(DOSUBL()) problem.  Hard to imagine a cause, definitely seems like one for tech support.

 

Amusingly, I asked google about it and got excited for a second before realizing that the AI had already ingested (and trusted) your post from a few hours ago:

dosubl.png

The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.

View solution in original post

5 REPLIES 5
sbxkoenk
SAS Super FREQ

Maybe you need a

proc scaproc;
   write;
run;

... as you can see here:
Usage Note 51875: Syntax for using the EXPANDMACROS option with the SCAPROC procedure
https://support.sas.com/kb/51/875.html

Also, if you are in SAS 9.4 windowing environment (display manager), then use program editor instead of enhanced editor:
Problem Note 51874: The SCAPROC procedure does not expand macros with the EXPANDMACROS option in the Enhanced Editor Window
https://support.sas.com/kb/51/874.html

 

BR, Koen

data_null__
Jade | Level 19

The issue is that when I run M_EXPAND_VARLIST something is closing the SCA recording JOBSPLIT: END  

The program functions properly it just stops recording.

This is all run SAS-Batch-Mode

 

data _null_;
   rc = dosubl('%trim(   proc contents data=sashelp.cars varnum; run;)');
   put rc=;
   run;

%if 1 %then %do;   /*Change 0 to 1 to see SCA file that ends after calling M_EXPAND_VARLIST*/
   %global classvars;
   %let classvars=%m_expand_varlist(data=sashelp.classfit,var=_CHARACTER_,out=expand);

/* JOBSPLIT: JOBENDTIME 03JUN2026:08:57:57.13 */
/* JOBSPLIT: END */
sbxkoenk
SAS Super FREQ

I cannot explain that. I'm sorry.

 

If no one else chimes in with a redeeming and saving remark, I would contact Technical Support.

 

SAS Technical Support:
Here is a link for your convenience: https://support.sas.com/en/technical-support.html#contact

 

BR, Koen

Tom
Super User Tom
Super User

Try this simplified example:

options ls=max mprint=1;
filename record temp;
proc scaproc;
   record record expandmacros opentimes;
run;

data x; x=1; run;

%global classvars;
%let classvars=NAME SEX;
%if 0 %then %do;
%let classvars=%m_expand_varlist(data=sashelp.classfit,var=_CHARACTER_,out=expand);
%end;
%if 1 %then %do;
%let classvars=%sysfunc(dosubl(%nrstr(proc summary data=x;output out=z;run;)));
%end;

%put NOTE: &=classvars;

proc summary data=x ;
  output out=y;
run;

proc scaproc;
 write;
run;

data _null_;
  infile record;
  input;
  list;
run;

Using %SYSFUNC(DOSUBL()) truncates the collection.

 21        /* JOBSPLIT: STEP SOURCE FOLLOWS */ 35
 22         0
 23        data x; x=1; run; 17
 24         0
 25        %global classvars; 18
 26        %let classvars=NAME SEX; 24
 27        %if 0 %then %do; 16
 28        %let classvars=%m_expand_varlist(data=sashelp.classfit,var=_CHARACTER_,out=expand); 83
 29        %end; 5
 30        %if 1 %then %do; 16
 31        %let classvars=%sysfunc(dosubl(%nrstr(proc summary data=x;output out=z;run;))); 79
 32         0
 33        /* JOBSPLIT: JOBENDTIME 03JUN2026:16:06:47.17 */ 48
 34        /* JOBSPLIT: END */ 19

But calling your macro does not truncate, instead it causes it to write gibberish.

 58        /* JOBSPLIT: STEP SOURCE FOLLOWS */ 35
 RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0                                                                                                                                                  
 
 59  CHAR  ................0 17
     ZONE  00000000000000003
     NUMR  00000000000000000
 60         0
...
 77        /* JOBSPLIT: STEP SOURCE FOLLOWS */ 35
 
 78  CHAR  ... ...@...a...p�w�D...Pevo....�.�2............��o�D...u.......��o�D...........��o�D...��o�D....... 
     ZONE  0002100400060007F7A470056760000E1A3000000000000CE6B4700700000008E6B470010000000AD6B4700AD6B470010002
     NUMR  000000000001000007F4F00056F0000DF1200000000000007F04F005000000001F04F00100000000FF04F000FF04F0020000
 
      101  ...`...Q...p�w�D...Pevo....�.�2............data x; x=1; 155
     ZONE  100600050007F7A470056760000E1A3000000000000667627327333
     NUMR  00000001000007F4F00056F0000DF12000000000000414108B08D1B
 79         0
 80        /* JOBSPLIT: TASKSTARTTIME 03JUN2026:16:12:39.10 */ 51
...

 

 

Quentin
Super User

Interesting. 

 

I could not replicate on Display Manager interactive SAS (9.4M7) but could when I ran in batch mode.

 

As you showed, it looks like it's not a %sysfunc() problem, or a DOSUBL problem, but a %sysfunc(DOSUBL()) problem.  Hard to imagine a cause, definitely seems like one for tech support.

 

Amusingly, I asked google about it and got excited for a second before realizing that the AI had already ingested (and trusted) your post from a few hours ago:

dosubl.png

The Boston Area SAS Users Group is hosting free webinars!

Register now at https://www.basug.org/events.

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand in the Innovate Hub.

Watch 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
  • 123 views
  • 3 likes
  • 4 in conversation