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

Innovate_SAS_Blue.png

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. 

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
  • 252 views
  • 2 likes
  • 4 in conversation