Hello,
I am trying to code a macro to get a column as a time period, which is called wantdate, It is accumulating till today every day. For example, if the startdate=01/01/2016, and enddate=02/27/2016. The wandate should cover the data as wantdate1, which is 01/01/2016, wantdate2, which is betweem 01/01/2016 and 01/02/2016, wantdate3, which is between 01/01/2016 and 01/03/2016,wantdate4, which is between 01/01/2016 and 01/04/2016.....and the last one is wantdate57, which is between 01/01/2016 and 02/27/2016. Is the code below good? If not, how to correct it? Thanks a lot!
%let startdate = 01jan2016;
%let enddate = 27feb2016;
*Number of loops;
%let iterations = %sysfunc(intck(day, "&startdate."d, "&enddate."d));
*Initialize new date variables four counting;
%let lowerdate = &startdate;
%let upperdate = %sysfunc(intnx(month, "&lowerdate"d, 11, end), date9.);
%put &lowerdate.;
%put &upperdate.;
%put &iterations;
%macro cases_per_year;
%do i = 1 %to &iterations;
/* proc sql noprint;*/
/* select count(zip)*/
/* into :nr_obs*/
/* from cases*/
/* where (diagdate GE "&lowerdate"d AND diagdate LE "&upperdate"d);*/
/* run;*/
/* quit;*/
*Increment both the lower and the upper boundary of the time interval by one year for the next iteration to count the numbers of the following year and so on;
%let lowerdate = %sysfunc( intnx(year, "&lowerdate"d, 1, beginning), date9.);
%let upperdate = %sysfunc(intnx(year, "&upperdate"d, 1, end), date9.);
%put &lowerdate.;
%put &upperdate.;
%end;
%mend cases_per_year;
%cases_per_year;
I don't think you need a macro and it's probably making your code too complex.
Can you post sample input data and sample output and explain your logic.
Also, do you have SAS/ETS?
Since it appears that your data has a date variable then perhaps you would want to look at this:
Proc freq data=cases;
tables diagdate;
format diagdate yearr4.;
run;
Or possibly
Proc freq data=cases;
tables diagnosisvariable * diagdate;
format diagdate yearr4.;
run;
sorry for confusing, I repost it to clarify.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.