Andy, I am certainly not an expert like Reeza and Astounding, however, I have a code style that has worked for me in the past in similar situations. When I want to build and populate variable names with numeric suffixes, I use a macro to build the array, name the variables in the array; and macro code to build the data step coding; This worked for me however I did include the "_t_" in the names. I also did not include any code to place default values in the members of the arrays'. With this style, using varnums, you can build as many new variables as you wish. data values; input date $7. var14 var41 8.; datalines; 2013M8 -25.6 -30 2013M9 -24.5 -27.3 2013M10 -26.4 -25.7 2013M11 -32.6 -29.2 2013M12 -30.7 -27.3 2014M01 -29.2 -30.3 ; run; title " values "; proc print data=values (obs=7); run; title " "; %macro bildit(varnums); proc sql; drop table work.wantvals; quit; data wantvals; set values; var140 = var14; var410 = var41; %do i=1 %to &varnums.; /* format the variable in the order you want them displayed/printed */ format var14&i. 8.; %end; %do i=1 %to &varnums.; format var41&i. 8.; %end; array lst14 {*} %do i=1 %to &varnums.; var14&i %end; ; array lst41 {*} %do i=1 %to &varnums.; var41&i %end; ; %do k=1 %to &varnums.; /* order of the variables has been set so they can be loaded in any order */ lst14{&k.} = lag&k.(var14); lst41{&k.} = lag&k.(var41); %end; drop var14 var41; run; %mend bildit; %bildit(6); title " wantvals "; proc print data=work.wantvals (obs=7); run; title " ";
... View more