简体   繁体   中英

SAS length of the value of the macro variable exceeds the maximum length

Hi I am trying to call a macro for each row in the data set using the code below

proc sql;
select cats('%run_procreg(name=',name,',month=',month,')') into :macrocalllist
  separated by ' ' from dataset_a;
quit;


&macrocalllist;

I am getting the 'variable maximum length' error:

SAS length of the value of the macro variable MACROCALLLIST (65540) exceeds the maximum length (65534). The value has been
truncated to 65534 characters.

because of the number of rows in the data set. Could you suggest a work-around?

Thank you,

CALL EXECUTE is one option. It allows you to generate a series of macro calls using data from a dataset, without storing the macro invocations in a macro variable.

For example:

%macro testprint(data=,obs=);
  proc print data=&data (obs=&obs);
  run;
%mend testprint;

data _null_;
  input datasetname $13. obs;
  call execute('%nrstr(%testprint(data='||datasetname
                               ||',obs='||put(obs,1.)
                               ||'))'
               );
  cards;
sashelp.shoes 3
sashelp.class 5
;

And the log will show:

NOTE: CALL EXECUTE generated line.
131  ;
1   + %testprint(data=sashelp.shoes,obs=3)    
NOTE: There were 3 observations read from the data set SASHELP.SHOES.   
2   + %testprint(data=sashelp.class,obs=5)    
NOTE: There were 5 observations read from the data set SASHELP.CLASS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM