: Here is some code that will cover all possibilities. You, of course, are responsible for insuring that it runs correctly. It ran for me and appears to produce the same results as your original code: /*specify input filename*/ %let fname=fisher; /*create some sample data*/ data &fname.; do i = 1 to 10; call streaminit(123); u1 = rand("Uniform"); b1 = ceil(5*u1); min1 = ceil(3*u1); max1 = ceil(2*u1); call streaminit(456); u2 = rand("Uniform"); b2 = ceil(5*u2); min2 = ceil(3*u2); max2 = ceil(2*u2); call streaminit(789); u3 = rand("Uniform"); b3 = ceil(5*u3); min3 = ceil(3*u3); max3 = ceil(2*u3); call streaminit(235); u4 = rand("Uniform"); b4 = ceil(5*u4); min4 = ceil(3*u4); max4 = ceil(2*u4); output; end; drop u1 u2 u3 u4 i; run; /*determine the value of maxvars*/ proc sql noprint; create table temp as select name from dictionary.columns where libname="WORK" and memname="%sysfunc(upcase(&fname.))" and upcase(name) like "MAX%" ; quit; %let maxvars=&sqlobs.; /*create the code*/ filename sascode temp; data _null_; length code stem part2 part3 part4 part5 end $255; file sascode; do i=105 to %eval(104+&maxvars.); part1=byte(i); if i eq 105 then do; part2='=1 %to &maxvars.;'; stem=catt('&',byte(i)); part3=catt('=b&',byte(i)); part4=catt('=min&',byte(i)); part5=catt('=max&',byte(i)); end='%end;'; code='%macro create_code;'; put code; code='data p&fname.;'; put code; code='set &fname.;'; put code; end; else do; part2=catt('=&',byte(i-1),'+1 %to &maxvars.;'); stem=catt(stem,'&',byte(i)); part3=catt(part3,'+b&',byte(i)); part4=catt(part4,'+min&',byte(i)); part5=catt(part5,'+max&',byte(i)); end=catt(end,'%end;'); end; code='%do '||part1||part2; put code; if i gt 105 then do; code=catt('py',stem,part3,';'); put code; code=catt('pymin',stem,part4,';'); put code; code=catt('pymax',stem,part5,';'); put code; code=catt('y_',stem,'=(py',stem,'-pymin',stem, ')/(pymax',stem,'-pymin',stem,'+0.0001);'); put code; end; if i eq %eval(104+&maxvars.) then do; put end; code='run;'; put code; code='%mend create_code;'; put code; end; end; run; /*include and run the created code*/ %include sascode /source2; %create_code data pydefs; set p&fname.;; keep y_:; run;
... View more