ID Car Date 1 MB 20MAR2023:06:01:27.967 2 EC 12FEB2022:06:01:27.967 3 DE 14APR2022:06:01:27.967 1 MB 29MAR2023:06:01:27.967 2 EC 29MAR2023:06:01:27.967
I want the dataset which has only todays date 29MAR2023:06:01:27.967
1 MB 29MAR2023:06:01:27.967 2 EC 29MAR2023:06:01:27.967
Can you provide more details on what you are looking to do?
I'm assuming you want to subset some SAS dataset to only provide data where some variable matches todays date
I recommend you review the documentation on SAS Date, Time, and Datetime Values
Maybe this will help you on your way
/* Create sample data set */
data work.have ;
format date date9. ;
do date="29MAR23"d to "05APR23"d ;
if date=today() then
value="I want these today" ;
else
value="I don't want these" ;
output work.have ;
end ;
run ;
/* Select observations where variable date is today */
data work.want ;
set have ;
if date=today() then
output work.want ;
run ;
If your date column is in SAS datetime format:
where datepart(date) = "&sysdate"d;
If it's a string:
where substr(date,1,9) = "&Sysdate9";
But this feels a bit static, what happends if you want to read yesterday's data?
@LinusH wrote:
If your date column is in SAS datetime format:
where datepart(date) = "&sysdate"d;
If it's a string:
where substr(date,1,9) = "&Sysdate9";
But this feels a bit static, what happends if you want to read yesterday's data?
Depending on environment the &sysdate may have problems if the SAS session runs long enough to cross date boundary.
SYSDATE Automatic Macro Variable
Contains the date on which a SAS job or session began executing.
If your SAS sessions run for long periods it may be better to use the Today(), or identical Date(), function which accesses the system date.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
For SAS newbies, this video is a great way to get started. James Harroun walks through the process using SAS Studio for SAS OnDemand for Academics, but the same steps apply to any analytics project.
Find more tutorials on the SAS Users YouTube channel.