BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
pkopersk
Fluorite | Level 6
%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?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

@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();

  

--
Paige Miller

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

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;

 

 

PaigeMiller
Diamond | Level 26

@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();

  

--
Paige Miller
Astounding
PROC Star
Better yet, skip the complications:

Days ="&sysdate9"d - startdate;

There is no reason to break the current date into pieces and reassemble the pieces.
Patrick
Opal | Level 21

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;

SAS Innovate 2025: Register Now

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!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 4098 views
  • 0 likes
  • 5 in conversation