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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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
  • 4 replies
  • 3830 views
  • 0 likes
  • 5 in conversation