DATA Step, Macro, Functions and more

Multiple dates

Accepted Solution Solved
Reply
Contributor
Posts: 27
Accepted Solution

Multiple dates

Hi,

I am doing some research on Crash data and I want to investigate few crashes happened on particular dates.

My data is in MDY format and these are the dates i  want to investigate (11/5/2017),(12/31/2017) &(01/04/2018) 

I know the function to select dates between two periods, not sure of selecting particular dates.

Your advice is much appreciated.

 


Accepted Solutions
Solution
‎02-01-2018 04:08 AM
PROC Star
Posts: 1,215

Re: Multiple dates

data want;
   set have;
   where date in ('05nov2017'd, '31dec2017'd, '04jan2018'd);
run;

View solution in original post


All Replies
Frequent Contributor
Posts: 109

Re: Multiple dates

  1. If the crash_date are in numeric form just displayed as 11/5/2017 in the dataset then you can try a datastep like following
    1. data output;
      set input;
      where crash_date in ('05Nov2017'd, '31Dec2017'd, '04Jan2018'd);
      run;
  2. But if the crash_date is characters then the following will work.
    1. data output;
      set input;
      where input(crash_date,mmddyy10.) in ('05Nov2017'd, '31Dec2017'd, '04Jan2018'd);
      run;
Contributor
Posts: 27

Re: Multiple dates

Posted in reply to Satish_Parida
Thanks for ur help, it works...cheers
Super Contributor
Posts: 370

Re: Multiple dates

Depends on the actual format of the dates stored in your table.

 

If the dates are in text format this might work:

data...

 set ...

 if date in ('11/5/2017' '12/31/2017' '01/04/2018');

run;

 

If the dates are in numeric format then this might work:

data...

 set ...

 if date in ('05NOV2017'd '31DEC2017'd '04JAN2018'd);

run;

 

//Fredrik

Solution
‎02-01-2018 04:08 AM
PROC Star
Posts: 1,215

Re: Multiple dates

data want;
   set have;
   where date in ('05nov2017'd, '31dec2017'd, '04jan2018'd);
run;
Contributor
Posts: 27

Re: Multiple dates

Thanks for ur help, it works...cheers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 137 views
  • 2 likes
  • 4 in conversation