Learning SAS? Welcome to the exclusive online community for all SAS learners.

Need to drop certain subject's data

Reply
Contributor
Posts: 66

Need to drop certain subject's data

[ Edited ]

I tried to drop a few subject's data from the dataset.

Could you help me delete those subjects' data using codes?

 

Here is what I tried:

 

data a1.Prediss1;
set a1.Prediss;
drop subject=5, 6, 15, 17;
where error=0;
run;

Super User
Posts: 23,937

Re: Need to drop certain subject's data

[ Edited ]

DROP is used to drop variables not observations, DELETE is used to delete observations.

 

Is there a subject variable that identifies, 5, 7, etc?

 

if so the code would look like:

 

if subject in (5, 6, 15, 17) then delete;

If there is no subject variable and its basically a record number you can use:

 

if _n_ in (5, 6, 15, 17) then delete;

_n_ is somewhat a row counter, but it really counts the number of iterations, so if you have explicit OUTPUT statements it messes things up, but for this type of situation should work fine. 

 


@nlpurumi wrote:

I tried to drop a few subject's data from the dataset.

Could you help me delete those subjects' data using codes?

 

Here is what I tried:

 

data a1.Prediss1;
set a1.Prediss;
drop subject=5, 6, 15, 17;
where error=0;
run;


 

Contributor
Posts: 66

Re: Need to drop certain subject's data

Wow, thanks! It worked!! Smiley Happy

 

 

Ask a Question
Discussion stats
  • 2 replies
  • 156 views
  • 1 like
  • 2 in conversation