BookmarkSubscribeRSS Feed
Smitha9
Fluorite | Level 6

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

3 REPLIES 3
AMSAS
SAS Super FREQ

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 ;
LinusH
Tourmaline | Level 20

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?

 

Data never sleeps
ballardw
Super User

@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.

 

sas-innovate-2024.png

📢

ANNOUNCEMENT

The early bird rate has been extended! Register by March 18 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

Register now!

From SAS Users blog
Want more? Visit our blog for more articles like these.
5 Steps to Your First Analytics Project Using SAS

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.

Discussion stats
  • 3 replies
  • 327 views
  • 2 likes
  • 4 in conversation