BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
akovach
Calcite | Level 5

Hello,

 

My over-research for something that I believe should be simple has caused me to be terribly confused on how to use today() function in a where statement. 

 

A column in my data is in the date format DATETIME22.3. I simply want to create subset that excludes any observations with a date greater than today.

 

All I want is to be able to reference today as a macro &today. as DATETIME22.3.

 

Thanks,

Autumn

 

/*this gives me 0 observations because today() appears to be a different format than activity_date_update*/

data latest_activity1;
set latest_activity;
if activity_date_update > today() then delete;
run;

/*this macros I found on my research appear to be used on for character macros*/

data _null_;
   call symputx('dt',put(date(),yymmddn8.);
run;

data latest_activity1;
set latest_activity;
if activity_date_update > &dt. then delete;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
gamotte
Rhodochrosite | Level 12

Hello,

 

SInce your column is in datetime format you can not compare it directly to a date.

Use the datepart function to extract the date from datetime.

 

where datepart(activity_date_update)>today();

View solution in original post

3 REPLIES 3
gamotte
Rhodochrosite | Level 12

Hello,

 

SInce your column is in datetime format you can not compare it directly to a date.

Use the datepart function to extract the date from datetime.

 

where datepart(activity_date_update)>today();

akovach
Calcite | Level 5

Thank you very much, my google searches let me down a very different path. 

ballardw
Super User

Pet peeve mixing up date and datetime values.


@akovach wrote:

 

A column in my data is in the date format DATETIME22.3. I simply want to create subset that excludes any observations with a date greater than today.

 

 


In SAS dates and datetimes are measured in different units: date uses days and datetime uses seconds. Proper use of the values involved will help in the long term.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 706 views
  • 1 like
  • 3 in conversation