Dear friends, Suppose I have many files, following the same structure, divided by Unit and Year (called Unit_Year_Itemized) on the disk. I need to make some calculation for all those files and put the results into one single file (Total_Summary). So now I have made a macro %Summary to do the calculation. The result is one single line, which can also be dumpted into a temp file (Unit_Year_Summary). Now I need to use this macro on all the Units and Years, years are numeric and maybe sequential, but units are strings, non sequential. And after the calculation is done, I need to put the results into one single file Total_Summary. For which I made a loop, trying to loop through a list of units, and Years, run the macro, and output the result into the Total_Summary. Of course, data step failed to recognize without set, and do loops failed. Of course, I can dump the intermediate files on the disk, and use a join or data step to manually put them into a single file. But if there are many files it becomes tidious. Thanks for any help to solve the problem. Ken Sample codes: /* Create testing input files, 2 units, 2 years */ data IT_2014_Itemized; infile cards delimiter=','; input Unit $ Year Client $ Sales; cards; IT,2014,Adam,100 IT,2014,John,200 IT,2014,Mary,150 ; run; data IT_2015_Itemized; infile cards delimiter=','; input Unit $ Year Client $ Sales; cards; IT,2015,Peter,130 IT,2015,John,350 IT,2015,Ted,600 ; run; data Support_2014_Itemized; infile cards delimiter=','; input Unit $ Year Client $ Sales; cards; Support,2014,Lou,80 Support,2014,Ann,700 Support,2014,Brian,320 ; run; data Support_2015_Itemized; infile cards delimiter=','; input Unit $ Year Client $ Sales; cards; Support,2015,Steve,440 Support,2015,Sam,530 Support,2015,Jack,200 ; run; /* Create macro to calculate for each unit and year, some summary results */ %macro Summary(Unit=, Year=); /* %let Unit=IT; */ /* %do Year=2014 %to 2015;*/ /* I can put a loop here to run all the years, but failed to run for all the units in a list */ proc sql; /* create table &Unit._&Year._Summary as */ /* This file is the intermediate summary file which can be dumped out in the disk */ select Unit, Year, count(Client) as Total_Client, sum(Sales) as Total_Sales, sum(Sales)/count(Client) as Average_Sales from &Unit._&Year._Itemized group by Unit, Year; quit; /* %end; */ %mend Summary; /* Now callthis macro for each unit and year */ %Summary(Unit=IT, Year=2014); /* Now I want to loop through all the units in the list, and the years, run the same macro with Unit and Year, and output the one-line per unit per year result into the Total_Summary file */ data Total_Summary; do Unit=IT, Support; /* This is a list of units, which can be many */ do Year=2014 to 2015; /* Year can be sequential */ %Summary(Unit=&Unit, Year=&Year); output; end; end; run;
... View more