Hi,
I want to use intnx on my date variable which is in the dateampm format.
My date variable has the value of "31Dec14:00:00:00"
I want to use the below code example.
Data _null_;
set callsymput('date1',put(intnx('month',today(),-1,'same'),date9.);
Run;
but when I use on my dataset date variable as mentioned below
date>"&date1". resulting 0 records even if there are records. Reason, it is in date time format.
Can someone help me how to use call symput on datetime variables
Thanks 🙂
Hi @Learn_SAS1 Please try using 'dtmonth' as the interval instead of month.
intnx('dtmonth',Your_datetime_var,-1,'same')
dtmonth should work for datetime values.
@Learn_SAS1 wrote:
Hi,
I want to use intnx on my date variable which is in the dateampm format.
My date variable has the value of "31Dec14:00:00:00"
I want to use the below code example.
Data _null_;
set callsymput('date1',put(intnx('month',today(),-1,'same'),date9.);
Run;
but when I use on my dataset date variable as mentioned below
date>"&date1". resulting 0 records even if there are records. Reason, it is in date time format.
Can someone help me how to use call symput on datetime variables
Thanks 🙂
I have no idea what you are doing here.
1. SET expects a data set name
2. callsymput() does not exist
3. There is no variable DATE anywhere
4. You cannot use date and datetime values in the same operation.
Either everything is date (and the interval is for example month) or everything is datetime (and the interval is for example dtmonth).
@Learn_SAS1 wrote:
Hi,
I want to use intnx on my date variable which is in the dateampm format.
My date variable has the value of "31Dec14:00:00:00"
I want to use the below code example.
Data _null_;
set callsymput('date1',put(intnx('month',today(),-1,'same'),date9.);
Run;
but when I use on my dataset date variable as mentioned below
date>"&date1". resulting 0 records even if there are records. Reason, it is in date time format.
Can someone help me how to use call symput on datetime variables
Thanks 🙂
Your value, if it has date and time components, is a DATETIME variable, not a Date. As such Date intervals cannot be used and get any expected result as the base units between Dates, days, and Datetime, seconds, are not compatible.
The intervals involving the date portion of a datetime variable in the Intnx or Intck functions start with DT, such as Dtday, Dtmonth, Dtquarter, Dtweek, Dtyear.
And if you compare dates to datetimes directly you very seldom get the correct result.
If Date is numeric this will fail with your attempt:
date>"&date1".
because, since attempted to apply a Format to the macro variable would be comparing a number to a value like "10SEP2020". SAS will attempt to convert strings to numbers or vice versa for comparisons but the macro variable AS FORMATTED can't be converted. If you intend to use a date literal it would have to have a d after the value as in "10SEP2020"d to be used as a date value. See the comparison of date and datetime again.
Did you have some code that worked before attempting this macro variable solution? If so, show an example. That is the first step: get code working without macro variables before creating the first macro variable. Then you know what your macro variable should look like.
Better to leave the macro variable as the numeric value instead of the formatted date/datetime/time unless you are using the value to write human readable text such as titles to simplify the code.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.