SAS Is it possible not to use "TO" in a do loop in MACRO? -


i used use %do ... %to , worked fine , when tried list character values without %to got message error: expected %to not found in %do statement

%macro printdb2 ;  %let thisname = ; %do &thisname = 'test1' , 'test2' , 'test3' ; proc print data=&thisname ; run ; %end ; %mend printdb2 ;   

i know how complete task using %to or %while . curious possible list character values in %do ? how can %do ?

if goal here loop through series of character values in macro logic, 1 approach take define corresponding sequentially named macro variables , loop through those, e.g.

%let mvar1 = a; %let mvar2 = b; %let mvar3 = c;  %macro example;     %do = 1 %to 3;         %put mvar&i = &&mvar&i;     %end; %mend example;  %example; 

alternatively, scan list of values repeatedly , redefine same macro var multiple times within loop:

%let list_of_values = b c;  %macro example2;     %do = 1 %to 3;         %let mvar = %scan(&list_of_values, &i, %str( ));         %put mvar = &mvar;     %end; %mend example2;  %example2; 

i've explicitly specified want use space list delimiter scan - otherwise sas uses lots default delimiters.


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -