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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.