SAS_learner
SAS_learner

Reputation: 521

month and year function combination is not giving expected results in SAS

I'm trying to delete all the rows that are in the BATCH: May-2014.

data out
set INPUT;
if MONTH(BATCH) NE 05 and YEAR(BATCH) NE 2014;
RUN;

Data in Batch column is Numeric in the format MONYY5.

EX:::: MAR13, APR14, MAY14, FEB14, JAN14, FEB12

After I run the code it is deleting all 2014 records instead of deleting MAY and 2014.

Thanks in advance.

Upvotes: 0

Views: 69

Answers (1)

Joe
Joe

Reputation: 63424

Because you're asking for everythign that is neither 2014 nor 05. You want everything that is not (both 2014 and 05).

data out
set INPUT;
if NOT (MONTH(BATCH) eq 05 and YEAR(BATCH) eq 2014);
RUN;

Another option if you know it's MONYY:

data out
set INPUT;
if vvalue(batch) ne 'MAY14'; *vvalue gives formatted value
RUN;

Only works if you're sure it's formatted that way, though.

Upvotes: 1

Related Questions