BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ody
Quartz | Level 8 Ody
Quartz | Level 8

Hello all,

 

I'm creating a date from a file name.

 

%let Today_chk = %sysfunc(inputn(%qsubstr(&fldate,5,2)%qsubstr(&fldate,7,2)%qsubstr(&fldate,3,2),mmddyy6.),date9.);
%put &Today_chk;

I'm trying to increment this date by 1 day and can't seem to get it to work.

 

I've tried intnx but it doesnt want to work for me.

%let Today_chk = intnx('day',%sysfunc(inputn(%qsubstr(&fldate,5,2)%qsubstr(&fldate,7,2)%qsubstr(&fldate,3,2),mmddyy6.),date9.),1);
%put &Today_chk;

 

What am I stumbling on? 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If you have a macro variable that contains an 8 digit string in the format YYYYMMDD you can convert it to an actual date value using the INPUTN() function which you can call using the %SYSFUNC() macro function.

 

%let date=%sysfunc(inputn(&fldate,yymmdd8));

 

This will be the number of days since 1/1/1960. If you want it formatted in a particular way you can use the optional format specification on the %SYSFUNC() function call.

 

%let datestr=%sysfunc(inputn(&fldate,yymmdd8),date9);

 

 

If you are using the value in an expression in SAS code (like an IF or WHERE statement) then you can use either format, but with the second you need to express it in the form of a date literal.

 

where visdate <= &date ;

where visdate <= &date + 1;

where visdate <= "&datestr"d ;

where visdate <= "&datestr"d+1 ;

 

If you need to generate the next date using the same YYYYMMDD format then use the PUTN() function and the YYMMDDN format.

 

%let nxtdate = %sysfunc(putn(1+%sysfunc(inputn(&fldate,yymmdd8)),yymmddn8));

View solution in original post

7 REPLIES 7
data_null__
Jade | Level 19

Show the value of FLDATE.

ballardw
Super User

Can you show us the value of &fldate ?

It may be that you can use the pieces without breaking them up using a different informat like YYMMDD6.

 

 

Ody
Quartz | Level 8 Ody
Quartz | Level 8

The file name is something like data_file_extract_20160219.tar.

 

&fldate = 20160219. I'm using it in another comparison in my program so I figured I could reuse it for what I'm trying to accomplish here. Ultimately I would like to incrememnt it by 1 day. It has to be a date value becuase I'm evaluating it against another date.

data_null__
Jade | Level 19

@Ody wrote:

The file name is something like data_file_extract_20160219.tar.

 

&fldate = 20160219. I'm using it in another comparison in my program so I figured I could reuse it for what I'm trying to accomplish here. Ultimately I would like to incrememnt it by 1 day. It has to be a date value becuase I'm evaluating it against another date.


I'm confused by your last statement as to what kind of date you are talking about.  Please provide more details everything and where the comparision of the value of FLDATE+1 will be used.  

ballardw
Super User

%let newdate =%eval(%sysfunc(inputn(&fldate,yymmdd8.)) + 1);

 

will create a value for newdate that is a SAS date value.

I'm not sure that is what you actually want as you were trying to do something with a DATE9 format.

If you need the result to look like a 20JUN2016

%let newdate =%sysfunc(putn(%eval(%sysfunc(inputn(&fldate,yymmdd8.)) + 1)),date9.));

Tom
Super User Tom
Super User

If you have a macro variable that contains an 8 digit string in the format YYYYMMDD you can convert it to an actual date value using the INPUTN() function which you can call using the %SYSFUNC() macro function.

 

%let date=%sysfunc(inputn(&fldate,yymmdd8));

 

This will be the number of days since 1/1/1960. If you want it formatted in a particular way you can use the optional format specification on the %SYSFUNC() function call.

 

%let datestr=%sysfunc(inputn(&fldate,yymmdd8),date9);

 

 

If you are using the value in an expression in SAS code (like an IF or WHERE statement) then you can use either format, but with the second you need to express it in the form of a date literal.

 

where visdate <= &date ;

where visdate <= &date + 1;

where visdate <= "&datestr"d ;

where visdate <= "&datestr"d+1 ;

 

If you need to generate the next date using the same YYYYMMDD format then use the PUTN() function and the YYMMDDN format.

 

%let nxtdate = %sysfunc(putn(1+%sysfunc(inputn(&fldate,yymmdd8)),yymmddn8));

Ody
Quartz | Level 8 Ody
Quartz | Level 8

Many thanks Tom (and Ballardw).

I couldn't quite figure out where to increment the date and your NXTDATE variable was a good example of how I needed to structure the code.

Thank you!

 

edit: In your NXTDATE variable, doesn't the putn change the date back to character or am I missing something?

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

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