DATA Step, Macro, Functions and more

Filter data based on date value

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Filter data based on date value

[ Edited ]

I just want to separate out the  passenger vehicles data launched after 20 april 14 .

sample dataset:-

 

Manufacturer Model   Latest Launch
Acura         Integra           2-Feb-14
Acura         TL                  22-Dec-15
Acura         CL                  23-Oct-15
Acura         RL                  5-Dec-14
Dodge         Ram Pickup          9-Nov-15
Dodge         Ram Wagon           13-Apr-14
Dodge         Ram Van             18-Apr-14
Dodge         Dakota              16-Jan-14
Dodge         Durango             17-Nov-15
Dodge         Caravan             6-Jun-14
Buick         Park Avenue         11-Feb-15
Buick         LeSabre             9-Mar-15
Cadillac      DeVille             23-Mar-14
Cadillac      Seville             23-Jul-15
Cadillac      DeVille             23-Feb-14
Cadillac      Seville             29-Apr-15

Accepted Solutions
Solution
a month ago
Regular Contributor
Regular Contributor
Posts: 162

Re: time

data cars;
	input 
	@1 manufacturer $8.
	@10 model $11. 
	@22 launch ddmmyy10.
	@33 type $;
	datalines;
Acura    Integra     02/02/2014 car
Acura    TL          22/12/2015 car
Acura    CL          23/10/2015 car
Acura    RL          05/12/2014 car
Dodge    Ram Pickup  09/11/2015 truck
Dodge    Ram Wagon   13/04/2014 wagon
Dodge    Ram Van     18/04/2014 van
Dodge    Dakota      16/01/2014 truck
Dodge    Durango     17/11/2015 truck
Dodge    Caravan     06/06/2014 car
Buick    LeSabre     09/03/2015 car
Buick    Park Avenue 11/02/2015 car
Cadillac DeVille     23/03/2014 car
Cadillac Seville     23/07/2015 car
Cadillac DeVille     23/02/2014 car
Cadillac Seville     29/04/2015 car
;
run;

*select cars after apr 20 2014;
data cars_after_april_20_2014;
	set cars;
	if launch > '20/Apr/2014'd;
	if type = 'car';
run;

Gives you

The SAS System      
       
manufacturer model launch type
Acura TL 20444 car
Acura CL 20384 car
Acura RL 20062 car
Dodge Caravan 19880 car
Buick LeSabre 20156 car
Buick Park Avenue 20130 car
Cadillac Seville 20292 car
Cadillac Seville 20207 car

View solution in original post


All Replies
Super User
Posts: 19,855

Re: time

What's the type and format on the DATE variable?

Is there something you've tried that doesn't work? If so, post the code and log please.

Occasional Contributor
Posts: 10

Re: time

Basically i am able to understand what i have to do in this question .

How should i separate the  vehicles type as i  only need passenger data .

Super User
Posts: 19,855

Re: time

Assuming you want to filter on date, you need to specify your date as the date9 format, with quotes and a D

 

where date > '01Jan2017'd;

This assumes your data has a numeric variable with a date format. Otherwise this does not apply.

 

This is a guess, because your question is unclear. If you want further help you need to take the time to detail your question.

Occasional Contributor
Posts: 10

Re: time

how should i separate vehicle data as i only want vehicle type=passenger ?

Super User
Posts: 19,855

Re: time


rajat1 wrote:

how should i separate vehicle data as i only want vehicle type=passenger ?


There's nothing shown in your sample above that would allow for that type of filtering.

 

This tutorial can help you learn how to filter your data

http://video.sas.com/detail/videos/sas-analytics-u/video/4573016761001/filtering-a-sas-table-in-a-da...

Regular Contributor
Regular Contributor
Posts: 162

Re: time

Do you have a vehicle type field in your data that you haven't shown us?

Occasional Contributor
Posts: 10

Re: time

[ Edited ]

Yes i am having

 

ManufacturerModelLatest LaunchVehicle type
Acura        Integra          2-Feb-14Passenger
Acura        TL               22-Dec-15Passenger
Acura        CL               23-Oct-15Passenger
Acura        RL               5-Dec-14Passenger
Dodge        Ram Pickup       9-Nov-15Passenger
Dodge        Ram Wagon        13-Apr-14Passenger
Dodge        Ram Van          18-Apr-14Car 
Dodge        Dakota           16-Jan-14Car 
Dodge        Durango          17-Nov-15Car 
Dodge        Caravan          6-Jun-14Car 
Buick        Park Avenue      11-Feb-15Passenger
Buick        LeSabre          9-Mar-15Passenger
Cadillac     DeVille          23-Mar-14Passenger
Cadillac     Seville          23-Jul-15Passenger
Cadillac     DeVille          23-Feb-14Passenger
Cadillac     Seville          29-Apr-15Passenger
Occasional Contributor
Posts: 10

Re: time

separate out the  passenger vehicles data launched after 20 april 14

 

Solution
a month ago
Regular Contributor
Regular Contributor
Posts: 162

Re: time

data cars;
	input 
	@1 manufacturer $8.
	@10 model $11. 
	@22 launch ddmmyy10.
	@33 type $;
	datalines;
Acura    Integra     02/02/2014 car
Acura    TL          22/12/2015 car
Acura    CL          23/10/2015 car
Acura    RL          05/12/2014 car
Dodge    Ram Pickup  09/11/2015 truck
Dodge    Ram Wagon   13/04/2014 wagon
Dodge    Ram Van     18/04/2014 van
Dodge    Dakota      16/01/2014 truck
Dodge    Durango     17/11/2015 truck
Dodge    Caravan     06/06/2014 car
Buick    LeSabre     09/03/2015 car
Buick    Park Avenue 11/02/2015 car
Cadillac DeVille     23/03/2014 car
Cadillac Seville     23/07/2015 car
Cadillac DeVille     23/02/2014 car
Cadillac Seville     29/04/2015 car
;
run;

*select cars after apr 20 2014;
data cars_after_april_20_2014;
	set cars;
	if launch > '20/Apr/2014'd;
	if type = 'car';
run;

Gives you

The SAS System      
       
manufacturer model launch type
Acura TL 20444 car
Acura CL 20384 car
Acura RL 20062 car
Dodge Caravan 19880 car
Buick LeSabre 20156 car
Buick Park Avenue 20130 car
Cadillac Seville 20292 car
Cadillac Seville 20207 car
Occasional Contributor
Posts: 10

Re: time

Thanks a lot Smiley Happy

☑ This topic is solved.

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

Discussion stats
  • 10 replies
  • 122 views
  • 2 likes
  • 3 in conversation