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?
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));
Show the value of FLDATE.
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.
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.
@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.
%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.));
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));
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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.