BookmarkSubscribeRSS Feed
DJENS
Calcite | Level 5
Hi everyone...

I have a SQL routine that pulls data from a large data warehouse. In it I have a where statement where one of the conditions is as follows:

Where AdmitDT>INTNX('Day', Today(), -181)

Basically, I want to count back and include those records where the AdmitDt is greater than 181 days prior to today. However, SAS does not like this statement at all. I have a feeling that I am doing something that completely demonstrates my lack of knowledge in handling dates and times in SAS. Any help would be appreciated.
4 REPLIES 4
P_J
Calcite | Level 5 P_J
Calcite | Level 5
Your statement works perfect to me bother data step and proc sql.

97 data test;
98 format AdmitDT yymmddn8.;
99 do i = 1 to 365;
100 AdmitDT = today() - i;
101 output;
102 end;
103 run;

NOTE: The data set WORK.TEST has 365 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds


104
105 data t;
106 set test;
107 if AdmitDT > INTNX('Day', Today(), -181);
108 run;

NOTE: There were 365 observations read from the data set WORK.TEST.
NOTE: The data set WORK.T has 180 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds


109
110 proc sql;
111 create table t1 as
112 select * from test
113 where AdmitDT > INTNX('Day', Today(), -181);
NOTE: Table WORK.T1 created, with 180 rows and 2 columns.

114 quit;
NOTE: PROCEDURE SQL used (Total process time):
real time 0.01 seconds
cpu time 0.01 seconds
Flip
Fluorite | Level 6
Are you running this in SAS or as a pass-thru. This is a SAS function which will not work if you run in a pass-Thru
Peter_C
Rhodochrosite | Level 12
to generate code filtering just the last 180 days, let the macro language help .... [pre] Where AdmitDT > "%sysfunc( INTNX( Day, '&sysdate9'd, -181),date9)"d [/pre]

PeterC
ArtC
Rhodochrosite | Level 12
Are there conditions where we cannot replace the INTCK with just
today()-181 ?

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 889 views
  • 0 likes
  • 5 in conversation