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.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 495 views
  • 2 likes
  • 4 in conversation