%let sysd= %sysfunc(day("&sysdate"d)); %let sysmonth= %sysfunc(month("&sysdate"d)); %let sysyear= %sysfunc(year("&sysdate"d)); %put &sysd &sysmonth &sysyear;
*this is what I tried to do; *%let sysd= %sysfunc(inputn(&sysd,4.0)); *%put &sysd; data main4; set main3; startdate=mdy(NMOIPMRI,NJOUPMRI,NANNPMRI); enddate=mdy(&sysmonth,&sysd,&sysyear); vehi_age=datdif(startdate,enddate,'act/act'); run;
Hello,
I am trying to count the number of days between today and a given date in the past.
I struggle to get the proper variable type to input in the mdy() function with my variables &sysd, &sysmonth, &sysyear.
Could you please help me?
@pkopersk wrote:
%let sysd= %sysfunc(day("&sysdate"d)); %let sysmonth= %sysfunc(month("&sysdate"d)); %let sysyear= %sysfunc(year("&sysdate"d)); %put &sysd &sysmonth &sysyear;
*this is what I tried to do; *%let sysd= %sysfunc(inputn(&sysd,4.0)); *%put &sysd; data main4; set main3; startdate=mdy(NMOIPMRI,NJOUPMRI,NANNPMRI); enddate=mdy(&sysmonth,&sysd,&sysyear); vehi_age=datdif(startdate,enddate,'act/act'); run;
Hello,
I am trying to count the number of days between today and a given date in the past.I struggle to get the proper variable type to input in the mdy() function with my variables &sysd, &sysmonth, &sysyear.
Could you please help me?
No macro variables needed at all.
All of this is very simple, and can be done in a single data step, by creating enddate differently.
enddate=today();
So if you macro variables that look like
8 %put &=sysd &=sysmonth &=sysyear; SYSD=27 SYSMONTH=2 SYSYEAR=2019
And you want to use them in a data step then just use them.
enddate=mdy(&sysmonth,&sysd,&sysyear);
No "conversion" is needed. No more than if you had just typed the digit 2 followed by the digit 7 into your program by hand.
Dates are number of days. If you want the difference in days then just subtract them.
days = enddate - startdate;
@pkopersk wrote:
%let sysd= %sysfunc(day("&sysdate"d)); %let sysmonth= %sysfunc(month("&sysdate"d)); %let sysyear= %sysfunc(year("&sysdate"d)); %put &sysd &sysmonth &sysyear;
*this is what I tried to do; *%let sysd= %sysfunc(inputn(&sysd,4.0)); *%put &sysd; data main4; set main3; startdate=mdy(NMOIPMRI,NJOUPMRI,NANNPMRI); enddate=mdy(&sysmonth,&sysd,&sysyear); vehi_age=datdif(startdate,enddate,'act/act'); run;
Hello,
I am trying to count the number of days between today and a given date in the past.I struggle to get the proper variable type to input in the mdy() function with my variables &sysd, &sysmonth, &sysyear.
Could you please help me?
No macro variables needed at all.
All of this is very simple, and can be done in a single data step, by creating enddate differently.
enddate=today();
Your code works for me. What error do you get?
%let sysd= %sysfunc(day("&sysdate"d));
%let sysmonth= %sysfunc(month("&sysdate"d));
%let sysyear= %sysfunc(year("&sysdate"d));
%put &sysd &sysmonth &sysyear;
data _null_;
startdate=today()-55;
enddate=mdy(&sysmonth,&sysd,&sysyear);
vehi_age=datdif(startdate,enddate,'act/act');
put vehi_age;
stop;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.