Hello I have a date issue, Given I have a macro variable
%let startdate = "30apr2012"d;
I want to find the last friday before that start date so example
it should be a macrovariable called myfriday= "27apr2012"d
Thanks for your help
Maybe not elegant but this seems to work:
%let mydate= %sysfunc(putn(&startdate,f10.)); /* need a numeric value to do arithmetic below*/
%let myfriday = %eval(%sysfunc(weekday(&startdate)) *(-1) -1 + &mydate);
%let myfriday = "%sysfunc(putn(&myfriday,date9.))"d; /* two lines for readability, might get this to work nesting functions*/
Code:
%let startdate = "30apr2012"d;
%let myfriday="%sysfunc(intnx(week.6,&startdate,0,b),date9.)"d;
%put myfriday: &myfriday;
Log:
15 %let startdate = "30apr2012"d;
16 %let myfriday="%sysfunc(intnx(week.6,&startdate,0,b),date9.)"d;
17 %put myfriday: &myfriday;
myfriday: "27APR2012"d
I think the only caveat is if hdg wants the previous Friday even when the date given is a Friday. Then the code would just need a -0.5 added to the date:
Code:
%LET startdate = "27apr2012"d;
%LET myfriday="%SYSFUNC(INTNX(WEEK.6,&startdate.-0.5,0),DATE9.)"d;
%PUT myfriday= &myfriday.;
Log:
15 %LET startdate = "27apr2012"d;
16 %LET myfriday="%SYSFUNC(INTNX(WEEK.6,&startdate.-0.5,0),DATE9.)"d;
17 %PUT myfriday= &myfriday.;
myfriday= "20APR2012"d
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.
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.