Using for loop indices in variable generation SAS -


i set loop in sas create time dependent tables.

the idea rather simple. have multiple tables left join them , operation every month. dont have experince in sas coding appreciate help. idea have follows:

for in [201401:201503] proc sql; create table try_i ## each month try_201401, try_201402 etc... select t1.var1 var1_i ##again similar above var1_201401, var_201402 etc.. t1  left join table2 t2 on condition1 ## not dependennt there index required    ... t1.var'i' not missinig ## in table t1, have specific variable specifies time period ex: var201405 

thanks lot in advance turan

a simple macro do:

%macro monthly_table( year, month);    proc sql;    create table try_&year.&month.    select t1.var1 var&year.&month. t1    left join .... on...    t1.var&year.&month. not missing;    quit; %mend monthlytable;  %macro reporting( year,month);   %do month =1 &month;       %monthly_table( &year, &month)   end; %mend reporting; 

in case not familiar macro:

the macro monthly_ table : %macro % mend used define macro, , &year &month return value supply between parentheses @ first line.

e.g. %monthlyrep ( 2004, 01) run proc sql statement based on year value = 2004 , month value = 01.

the macro reporting : loop through months in year. 2015, have specify within parentheses e.g.

%report( 2015, 01) = 201501  

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -