BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Kirito1
Quartz | Level 8

I was working on a dataset in SAS and I want to filter out data based on date. So right I am using this as a code.

data want;
set have;
where ('09JAN2023'd <= DATE_OF_APPROVAL <= '10JAN2023'd);
run;

Now, I want to use today as a function to do the above task so that everyday when I run code it takes the below logic.

 

data want;

set have;

where ((today()-2) <= DATE_OF_APPROVAL <= (today()-1));

run;

(the logic is based on today's date like if today is 11JAN2023 it should bring date of 09JAN2023 and 10JAN2023).

I just want guidance in approaching this problem.

Is this possible somehow in SAS. Please, help!!

 

Thanks

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

@Kirito1 wrote:

I was working on a dataset in SAS and I want to filter out data based on date. So right I am using this as a code.

data want;
set have;
where ('09JAN2023'd <= DATE_OF_APPROVAL <= '10JAN2023'd);
run;

Now, I want to use today as a function to do the above task so that everyday when I run code it takes the below logic.

 

data want;

set have;

where ((today()-2) <= DATE_OF_APPROVAL <= (today()-1));

run;

(the logic is based on today's date like if today is 11JAN2023 it should bring date of 09JAN2023 and 10JAN2023).

I just want guidance in approaching this problem.

Is this possible somehow in SAS. Please, help!!

 

Thanks

 


When in doubt try it:

data have;
   input datevar :date9.;
   format datevar date9.;
datalines;
08Jan2023
09Jan2023
10Jan2023
11Jan2023
12Jan2023
13Jan2023
14Jan2023
;

data want;
   set have;
   where (today()-2) le datevar le (today()-1);
run;

 

View solution in original post

5 REPLIES 5
ballardw
Super User

@Kirito1 wrote:

I was working on a dataset in SAS and I want to filter out data based on date. So right I am using this as a code.

data want;
set have;
where ('09JAN2023'd <= DATE_OF_APPROVAL <= '10JAN2023'd);
run;

Now, I want to use today as a function to do the above task so that everyday when I run code it takes the below logic.

 

data want;

set have;

where ((today()-2) <= DATE_OF_APPROVAL <= (today()-1));

run;

(the logic is based on today's date like if today is 11JAN2023 it should bring date of 09JAN2023 and 10JAN2023).

I just want guidance in approaching this problem.

Is this possible somehow in SAS. Please, help!!

 

Thanks

 


When in doubt try it:

data have;
   input datevar :date9.;
   format datevar date9.;
datalines;
08Jan2023
09Jan2023
10Jan2023
11Jan2023
12Jan2023
13Jan2023
14Jan2023
;

data want;
   set have;
   where (today()-2) le datevar le (today()-1);
run;

 

Kirito1
Quartz | Level 8
It only is getting data on date of (today -2 )
Kurt_Bremser
Super User

Then you don't have dates for today()-1 in the dataset.

From where do your dates originate? If you imported from Excel, your dates may have invisible time components (Excel stores times as fraction of a day, not as count of seconds, and has therefore only datetime values).

ballardw
Super User

@Kirito1 wrote:
It only is getting data on date of (today -2 )

With the code shown above creating the data set and running on 11JAN2023 the result I get is

Obs datevar
1 09JAN2023
2 10JAN2023

 

If you are not getting such then perhaps you do not have a value in your set that your expect.

Kirito1
Quartz | Level 8
Nah using it directly is working something like below.
data want;
set have;
where today()-3 <= DATE_OF_APPROVAL <= today();
run;
Thanks for the contribution. 🙂

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!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 856 views
  • 2 likes
  • 3 in conversation