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

Hi everyone,

 

I'm still pretty new to sas.

Here is the situation.

 

I have a table (Merged1) that has IDnumbers some descriptions and 2 dates, an event date and a consent date. both of the dates are in the format MMDDYY10 and each row has all these variables.

I want to get a data set where the consent date is before the event date. So if an even happened before the consent it will not be in my new data set. I have something like this...

 

data Sample1;

    set merged_data;

    where event_date > consent_date;

run;

 

I know that dates are just numbers counting from a certain date, so I would imagine this would work, but that is not the case.

 

please and thank you

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

If your two dates are just character strings that look like dates, just change your code to:

 

data Sample1;
    set merged_data;
    if input(event_date,mmddyy10.) > input(consent_date,mmddyy10.);
run;

HTH,

Art, CEO, AnalystFinder.com

 

 

 

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

Make sure (proc contents) that the date variables are numeric with a MMDDYY10. assigned.

If that is the case, post some examples that illustrate your issues in a data step with datalines.

Reeza
Super User

@Curly wrote:

Hi everyone,

 

I would imagine this would work, but that is not the case.

 

please and thank you

 

 


What does that mean? How did it not work?

art297
Opal | Level 21

If your two dates are just character strings that look like dates, just change your code to:

 

data Sample1;
    set merged_data;
    if input(event_date,mmddyy10.) > input(consent_date,mmddyy10.);
run;

HTH,

Art, CEO, AnalystFinder.com

 

 

 

ballardw
Super User

Example data.

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.

SuryaKiran
Meteorite | Level 14

You need to look into the descriptor portion about how the dates are formated. Use PROC CONTENTS and see weather the dates are char or num and use appropriate method as mentioned by others.

Thanks,
Suryakiran

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
  • 5 replies
  • 22360 views
  • 2 likes
  • 6 in conversation