Reputation: 13
Hi I am trying to import data (successfully) from a folder that is a date so the file path reads /year/month/date (*today's date)
I am then tweaking some of the data (again successfully). Once that is done I want to export it to a folder that is 29 days forward from the folder I took it from.
Here is my current macro:
%LET TODAY = %SYSFUNC(TODAY());
%PUT &TODAY;
%LET TODAYA = %SYSFUNC(PUTN(&TODAY,DDMMYYn8.));
%PUT &TODAYA;
%LET TWENTYNINE = %SYSFUNC(PUTN(&TODAY.+29,DDMMYYn8.));
%PUT &TWENTYNINE;
%LET T_DATE = %SYSFUNC(PUTN(&TODAY,DDMMYYn8..));
%LET T_YEAR = %SYSFUNC(YEAR(&TODAY));
%LET T_MONTH = %SYSFUNC(MONTH(&TODAY));
%LET P_DATE = %SYSFUNC(PUTN(&TWENTYNINE,DDMMYYn8..));
**%PUT &P_DATE;
%LET P_YEAR = %SYSFUNC(YEAR(&P_DATE));
%LET P_MONTH = %SYSFUNC(MONTH(&P_DATE));**
The P_Date reveals the error:
ERROR: Argument 1 to function MONTH referenced by the %SYSFUNC or %QSYSFUNC macro function is not a number. ERROR: Invalid arguments detected in %SYSCALL, %SYSFUNC, or %QSYSFUNC argument list. Execution of %SYSCALL statement or %SYSFUNC or %QSYSFUNC function reference is terminated.
But I cant get my head around it any help would be massively appreciated.
Upvotes: 1
Views: 403
Reputation: 51581
If you want to determine the source path to use for today's date then use the TODAY()
function. You can apply the YYMMDDS
format to have it displayed as YYYY/MM/DD.
%let frompath=%sysfunc(today(),yymmdds10);
If you want to calculate the target path from the source path then you can use the INPUTN()
function to convert it back to a date, add 29 and use PUTN()
function to convert it back to a string.
%let topath=%sysfunc(putn(29+%sysfunc(inputn(&frompath,yymmdd10)),yymmdds10));
Upvotes: 0
Reputation: 10411
Imbricating %sysfunc's is handy:
%LET P_YEAR = %SYSFUNC(YEAR(%SYSFUNC(TODAY())+29));
%LET P_MONTH = %SYSFUNC(MONTH(%SYSFUNC(TODAY())+29));
%PUT &P_YEAR &P_MONTH;
Results in:
2016 2
EDIT
(Try solving it by yourself first, but here's a full solution...)
data _null_;
target = today() + 29;
format target YYMMDDS10.;
put target=;
call symput("target", put(target, YYMMDDS10.));
run;
%put ⌖
2016/02/24
Upvotes: 0