BookmarkSubscribeRSS Feed
Fluorite | Level 6



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.;


%mend cases_per_year;


Super User

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?

Super User

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.;



Or possibly


Proc freq data=cases;

   tables diagnosisvariable * diagdate;

   format diagdate yearr4.;


Fluorite | Level 6

sorry for confusing, I repost it to clarify.



Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.


Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 


Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 3 in conversation