DATA Step, Macro, Functions and more

drop observations with certain value

Reply
Contributor
Posts: 20

drop observations with certain value

Hi,

 

I have a data set data1 and want to drop observations where month larger than t, and save the new data as data2.

 

How shall I do this?

 

Thanks 

Trusted Advisor
Posts: 1,146

Re: drop observations with certain value

[ Edited ]

Please provide a sample data of the variables you have with values. This will help to get better responses. Without the data it is very difficult to suggest the code.

Thanks,
Jag
Trusted Advisor
Posts: 1,826

Re: drop observations with certain value

Posted in reply to Jagadishkatam

Is January 2017 greater then December 2016 ?

Are you comparing just the month or the date ?

In what format is your date? Is Character? numeric? sas date?

If it is a character date - is it ddmmyy mmddyy or any othe format ?

 

The code will change according to your answer.

The best is to post example of your data.

Super Contributor
Posts: 320

Re: drop observations with certain value

[ Edited ]

Suppose you are interested to drop  all observations of SASHELP.CLASS where AGE = 14 to get new data as myclass.

 

data myclass;

     set sashelp.class;

     where AGE ^= 14;

run;

If you interested to drop those whose SEX = 'M' then do:

data myFemale;

    set sashelp.class;

       where Sex ^= 'M';

run;

Contributor
Posts: 54

Re: drop observations with certain value

Data data2;
Set data1;
If (month>t) then output data2;
Run;
Ask a Question
Discussion stats
  • 4 replies
  • 199 views
  • 0 likes
  • 5 in conversation