I am attempting to build a process and to make sure all of my dates are consistent I'm trying to do something like the following. I need these various formats for various data inputs that only accept certain types, so I'm trying to make all my variables be modified with just one change each week.
%let Start_Date_Time=2019-01-01 00:00:00;
%let End_Date_Time=2020-04-03 00:00:00;
%let Start_Date = %Sysfunc(datepart(%Sysfunc(input(&Start_Date_Time),yymmdd10.)));
%let End_Date = %Sysfunc(datepart(%Sysfunc(input((&End_Date_Time),yymmdd10.)));
%let Begin_Week=%Sysfunc(week(&Start_Date));
%let End_Week=%Sysfunc(week(&End_Date));
When I do this I get an error that input is not a supported function for %sysfunc, is there an alternate way to get at what I'm trying to do?
From the online documentation of %sysfunc and functions not allowed:
Note: Instead of INPUT and PUT, which are not available with %SYSFUNC and %QSYSFUNC, use INPUTN, INPUTC, PUTN, and PUTC.
What @ballardw says.
Alternatively use a data _null_; step and create the macro variables using call symputx(); This will make your code easier to read.
Also applying the function DATEPART to a date , i.e. input (somevar, yymmdd10.) is almost certainly not what you you want.
The datepart function will assume the argument is a datetime value, which is measured in seconds and so the value will be treated quite differently than a date that you already have.
data example; x="2019-01-01 00:00:00"; y= input(x,yymmdd10.); put y= date9.; z=datepart(y); put z= date9.; run;
https://communities.sas.com/t5/SAS-Communities-Library/Working-with-Dates-and-Times-in-SAS-Tutorial/... has a PDF with much information about dates.
I think the problem is with your first two %SYSFUNC calls. You use:
%Sysfunc(datepart(%Sysfunc(input(&Start_Date_Time),yymmdd10.)))
which makes "yymmdd10." a parameter for the %SYSFUNC macro function (it will return a value formatted that way), probably read with the BEST32. format (giving an invalid value).
If you change it to
%Sysfunc(input(&Start_Date_Time,yymmdd10.))
so that it becomes a parameter for the INPUT function, I think you will get what you want (a SAS date value, which can be used in the next calculations). There is no need to use the DATEPART function, as the YYMMDD10. format will only read the first 10 characters, and convert it to a SAS date value.
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 16. 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.