Bab
Bab

Reputation: 443

How to delete some observations in SAS?

I'm trying to learn SAS by coding. Currently, I'm trying to use an if statement for an imported dataset from an excel sheet. However, I'm facing an issue with the if statement. I think it's because the syntax is wrong. What I have read, is that an if statement can be used in a data step.

What I want to achieve is to delete some observations - If the gender is not female, then it has to delete the observation.

This is how I have tried to do:

proc import datafile="C:\Users\User\Desktop\test.xlsx"

DBMS=XLSX 

out=onlyF;
if Gender != 2 then delete;
run;

The variable name is Gender.

The error I get is for "if": Statement is not valid or it is used out of proper order.

Upvotes: 1

Views: 196

Answers (1)

H_J
H_J

Reputation: 486

As a general rule in SAS "if" condition only works when the data resides in PDV whereas "where" condition works even before data moves to PDV. As in your case you are trying to read the external file so "if" would never work. Try below code

proc import datafile="C:\Users\User\Desktop\test.xlsx"

DBMS=XLSX 

out=onlyF(where=(Gender eq 2));

run;

Upvotes: 3

Related Questions