SAS do loop with array -
i first store character elements of array size 3.
data _null_; array fruit[3] $10 ("apple" "orange" "lemon"); call symput("fruit1", fruit1); call symput("fruit2", fruit2); call symput("fruit3", fruit3); run;
i print element of array fruit
,
%put &fruit1; %put &fruit2; %put &fruit3;
is possible using do-loop?
i prefer sql method create variables. here's 2 ways display macro variables, 1 using data step , 1 using macro loop:
*generate sample data; data have; input fruit $20.; cards; apple banana grapes ; run; *create macro variables; proc sql noprint; select fruit :fruit1-:fruit1000 have; quit; *store number of macro variables; %let nobs=&sqlobs.; %put &nobs; *display macro variables in data step; data _null_; i=1 &nobs.; have=symget(catt("fruit", i)); put have; end; run; *display macro variables using macro logic; %macro display_vars; %do i=1 %to &nobs.; %put &&fruit&i.; %end; %mend; %display_vars;
Comments
Post a Comment