BookmarkSubscribeRSS Feed
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;

 

 

2 REPLIES 2
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 */

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