Help using Base SAS procedures

how to macro a accumulating time period

Reply
Contributor
Posts: 74

how to macro a accumulating time period

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;

Super User
Posts: 17,868

Re: how to macro a accumulating time period

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
Posts: 10,516

Re: how to macro a accumulating time period

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;

Contributor
Posts: 74

Re: how to macro a accumulating time period

sorry for confusing, I repost it to clarify.

Ask a Question
Discussion stats
  • 3 replies
  • 185 views
  • 0 likes
  • 3 in conversation