Help using Base SAS procedures

delete observations

Reply
Contributor
Posts: 58

delete observations

Hello, First time here. I have a data set where i would like to remove observations which equal a particular value of a variable. Here's what i've got:

data st.Def_2008;
delete all where (ResultType=77);
run;

Here's the error i get:
ERROR 79-322: Expecting a ;.

ERROR 76-322: Syntax error, statement will be ignored.

Help?
Super Contributor
Posts: 345

Re: delete observations

You should read the "SAS 9.2 Language Reference: Concepts, Second Edition", especially the chapter about "DATA step concepts".

Link: http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#/documentation/cdl/e...
Super User
Posts: 10,028

Re: delete observations

> data st.Def_2008;
> delete all where (ResultType=77);

Why not use 'not' operation symbol.

data st.Def_2008;
where ResultType ne 77 ;
Super Contributor
Super Contributor
Posts: 3,174

Re: delete observations

There definitely needs to be more substance to the DATA step - either a SET (providing an input SAS member) or some type of assignment statements to derive one or more SAS variables and then use an IF THEN DELETE; or some similar-result oriented coding technique.

However, as was suggested, the SAS DOC and other supplemental technical reference material hosted at SAS.COM support website will be quite useful to the original poster.

Scott Barry
SBBWorks, Inc.
Super User
Posts: 10,028

Re: delete observations

Thanks . Sbb.
There are more things i have to learn.And also forget SasKiwi's right code.Smiley Sad
Regular Contributor
Posts: 191

Re: delete observations

Try sql instead:

proc sql;
delete *
from st.Def_2008
where ResultType=77
;
quit;
Contributor
Posts: 58

Re: delete observations

Thanks so much for all the help everyone! Proc SQL seems like what I'm really looking for! I have multiple situations to eliminate observations and it's what is easiest for me to get a handle on.
Super User
Posts: 3,252

Re: delete observations

The equivalant DATA step logic is:

data st.Def_2008;
set st.Def_2008;
if ResultType=77 then delete;
run;

The advantage of the DATA step is you can do a lot more in the same step with only one pass of the data than you can in SQL, for example create more than one output dataset containing different results.
Regular Contributor
Posts: 191

Re: delete observations

One advantage with proc sql is that index is kept and that you don't rewrite the table, useful when working with larga ds...
Occasional Contributor
Posts: 8

Re: delete observations

Just try this code:

data st.Def_2008; /*Destination dataset */
set st.Def_2008; /*Source dataset*/
if ResultType=77 then delete;

It should delete that particular value from the dataset.
Super Contributor
Super Contributor
Posts: 3,174

Re: delete observations

Also consider using a WHERE statement, if appropriate, for efficiency.

Scott Barry
SBBWorks, Inc.
Ask a Question
Discussion stats
  • 10 replies
  • 164 views
  • 0 likes
  • 7 in conversation