Resolving a macro value as a date

Accepted Solution Solved
Reply
Frequent Contributor
Frequent Contributor
Posts: 133
Accepted Solution

Resolving a macro value as a date

I need help using a date in a macro variable. I cannot create sample datalines with the right format but hopefully someone can also help me create datalines in this sample based on my explanation. 

 

I have set a variable called pulldate equal to a literal at the start of a program. I then need to create a new end date based on the proximity to the pull date. In this particular situation I need a date literal so that it can be used in a calculation. If the current enddate is greater than the &pulldate minus 7 days then make the new enddate equal to the &pulldate plus 7 days. 

 

%Let PullDate="5/27/16"d;

Data want ;
input enddate mmddyy10.;
format enddate mmddyy10. ;
datalines;
12/12/2014
12/15/2014
04/19/2016
10/06/2014
;
if EndDate > &pullDate. - 7 then EndDate = &pulldate. - 7 ;

run;


Accepted Solutions
Solution
‎08-09-2016 10:30 PM
Grand Advisor
Posts: 10,210

Re: Resolving a macro value as a date

Date literals MUST be in the form of 'ddMONyy'd or 'ddMONyyyy';

Also program lines come before datalines

 

Your range of data examples do not make much sense for the given Pulldate but I think this is what you may want

 

%Let PullDate="27may2016"d;

Data want ;
input enddate mmddyy10.;
format enddate mmddyy10. ;
if EndDate > (&pullDate. - 7) then EndDate = &pulldate. +7 ;

datalines;
12/12/2014
12/15/2014
04/19/2016
10/06/2014
;

run;

View solution in original post


All Replies
Solution
‎08-09-2016 10:30 PM
Grand Advisor
Posts: 10,210

Re: Resolving a macro value as a date

Date literals MUST be in the form of 'ddMONyy'd or 'ddMONyyyy';

Also program lines come before datalines

 

Your range of data examples do not make much sense for the given Pulldate but I think this is what you may want

 

%Let PullDate="27may2016"d;

Data want ;
input enddate mmddyy10.;
format enddate mmddyy10. ;
if EndDate > (&pullDate. - 7) then EndDate = &pulldate. +7 ;

datalines;
12/12/2014
12/15/2014
04/19/2016
10/06/2014
;

run;
Frequent Contributor
Frequent Contributor
Posts: 133

Re: Resolving a macro value as a date

thank you but I ran the code like this and I got the following results:

%Let PullDate="27may2016"d;

Data want ;
input enddate mmddyy10.;
format enddate mmddyy10. ;
if EndDate > &pullDate. - 7 then EndDate = &pulldate. - 7 ;

datalines;
'12/12/2014'
'12/15/2014'
'04/19/2016'
'10/06/2014'
;

run;

 

Log Results:

 


8369 %Let PullDate="27may2016"d;
8370
8371 Data want ;
8372 input enddate mmddyy10.;
8373 format enddate mmddyy10. ;
8374 if EndDate > &pullDate. - 7 then EndDate = &pulldate. - 7 ;
8375
8376 datalines;

NOTE: Invalid data for enddate in line 8377 1-10.
RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----
8377 '12/12/2014'
enddate=. _ERROR_=1 _N_=1
NOTE: Invalid data for enddate in line 8378 1-10.
8378 '12/15/2014'
enddate=. _ERROR_=1 _N_=2
NOTE: Invalid data for enddate in line 8379 1-10.
8379 '04/19/2016'
enddate=. _ERROR_=1 _N_=3
NOTE: Invalid data for enddate in line 8380 1-10.
8380 '10/06/2014'
enddate=. _ERROR_=1 _N_=4
NOTE: The data set WORK.WANT has 4 observations and 1 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


8381 ;
8382
8383 run;

 

Thank you for your suggestions. I welcome any others. 

 

 

Respected Advisor
Posts: 4,973

Re: Resolving a macro value as a date

So why did you add quotes around the raw data lines?  The program works without them.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 301 views
  • 1 like
  • 3 in conversation