Hi Kurt
Thanks for the solution, really appreciate that..
now i I am just trying to understand the code , is symputx function is used to convert the date in to character value , could you please
elaborate the whole code step by step as I am not familiar with symputx, put dims and the use input, if you could help me understand this code then it will be very beneficial for my learning. Please advise.
thanks
Tk
First of all, symputx is not a function, it is a call routine (in Pascal such a thing is called a procedure, the generic name in programming is subroutine; C does not have it, it is defined there as a function without a return value, eg void myproc();)
It does not return a value and always needs the call keyword.
Having said that, let's dissect one of the statements from outside in:
call symputx('startmonth',something_complicated_here);
The first parameter (or argument) to call symputx is the name of a macro variable to be created. The second parameter is the value that should go into this new macro variable. An optional third parameter would specifiy if the variable is to be created in the local ('l') or global ('g') symbol table.
Next layer:
put(some_number,best.)
Since call symputx (and call symput, BTW) want a character value as their second argument, I use the put() function to prevent any automatic conversion (I like to have complete control over what the computer does for me). The additional leading blanks from the best. format are being taken care of by call symputx.
Next layer:
dhms(input("&start.-01",yymmdd10.),0,0,0)
The dhms() function computes a datetime value from 4 parameters: date, hours, minutes, seconds. The date needs to be a valid SAS date value (number of days calculated from 1960-01-01, back in time to 1582, and forward to 19999, but limited by the four digits for years in most date formats)
Innermost layer:
input("&start.-01",yymmdd10.)
Make a yyyy-mm-dd string from your macro variable, and use the proper informat to convert the string to a SAS date value.
Quote:
The dhms() function computes a datetime value from 4 parameters: date, hours, minutes, seconds
It may not be relevant, since you already have a solution. But here is the point I was trying to make. Perhaps this will help you frame questions in the future.
Here's what you started asking for:
where d_entry >= '2016-11-01 00:00:00.000' and d_entry < '2017-10-01 00:00:00.000' ;
Here's what you actually needed (using a different date range, but that's not the point here):
where d_entry >= "01JUN2017:00:00:00.000"dt and d_entry < "01SEP2017:00:00:00.000"dt ;
You need to realize that these statements are different, and the solution will vary depending on what you actually need.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.