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 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1136 views
  • 0 likes
  • 5 in conversation