BookmarkSubscribeRSS Feed
A_SAS_Man
Pyrite | Level 9

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?

4 REPLIES 4
ballardw
Super User

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.
Patrick
Opal | Level 21

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.

ballardw
Super User

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.

s_lassen
Meteorite | Level 14

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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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