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
@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 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;
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).
@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
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!
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.