Try the code below.
I used sashelp.prdsal2 --> it has fields similar to your case (year, state). The code will perform single data read with multiple writes.
Hope it helps,
Ahmed
proc sql noprint; select distinct cats('WORK.',translate(STRIP(state),'_',' '),'_',year) ,cat ('WHEN (year=',year,' and state="',STRIP(state),'") OUTPUT WORK.',translate(STRIP(state),'_',' '),'_',year,';') into :g_outputNames separated by ' ' ,:g_conditions separated by ' ' from sashelp.prdsal2 order by year; quit; /* %put g_outputNames = %superq(g_outputNames); %put g_conditions=%superq(g_conditions); */ DATA &g_outputNames; SET sashelp.prdsal2; SELECT; &g_conditions OTHERWISE; END; RUN;
... View more