BookmarkSubscribeRSS Feed
zhangda
Fluorite | Level 6

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;

3 REPLIES 3
Reeza
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?

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

run;

 

Or possibly

 

Proc freq data=cases;

   tables diagnosisvariable * diagdate;

   format diagdate yearr4.;

run;

zhangda
Fluorite | Level 6

sorry for confusing, I repost it to clarify.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 870 views
  • 0 likes
  • 3 in conversation