I wrote a program that reads in data that looks like this:
ID | Type | Gender | Ethnicity | _start | _end | rank |
1001549 | P | Male | 1 | 24-Mar-17 | 23-Mar-19 | 2 |
1001549 | CS | Male | 1 | 16-Mar-15 | 14-Jun-17 | 1 |
and analyzes that data to create daily population data that will look like this:
rank | Gender | Ethnicity | Snapshot | Type | count |
1 | Male | 0 | 1-Apr-17 | CS | 1 |
Rather than running that program 365 times, changing the date each time, I thought I could put it into a macro. But I can't figure out how to increase the date each iteration. Here's the program that I have written so far.
%let date = '01apr2017'd;
*read in the programs data and keep only the programs that were active on the snapshot date;
*sort by client id, then by the rank of their programs that were active on that day;
proc sort data=Intakes1 out = a;
where _start <= &date <= _end;
by id rank;
run;
*for each client, keep the program that is ranked highest on that date;
data b;
set a;
by id;
if first.id;
snaphot = &date;
count = 1;
format snapshot date9.;
run;
*sort to prepare for proc summary;
proc sort;
by rank gender ethnicity;
run;
*aggregate the program records to get a total count of clients, categorized by their highest ranked program;
proc summary nway;
class rank gender ethnicity;
var count;
id snapshot type;
output out=c sum=;
run;
*add the results of c to the daily dataset;
*the daily dataset will be used to create a fiscal year average of clients, analyzed by type of program/gender/ethnicity;
data daily (drop = _type_ _freq_);
set daily c;
run;
*delete the work datasets and start again;
proc datasets library = work nolist;
delete a b c;
quit;
run;
I'd like the macro to repeat for each day in the fiscal year. I thought I could start with
%macro repeat(n);
%do I=1 %to &n.;
and end with
%end;
%mend repeat;
%repeat(365); (although would have to modify that during a leap year);
but I just can't figure out how to manage the date to increase it each time and use it through all of those proc and data steps.
Thanks for any help that you can provide! I am using SAS 9.4.