BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jspoend
Obsidian | Level 7

Hi there, 

 

I have 2 datafiles. 

 

Claims_file: all claims during pregnancy of women insured with a certain insurer

pregID date_claim ATC

1 mmddyy xy

1 mmddyy xy

1 mmddyy xy

2 mmddyy xy

2 mmddyy xy

3 mmddyy xy

3 mmddyy xy

3 mmddyy xy

4 mmddyy xy

4 mmddyy xy

 

abortions_file: IDs of pregnancies which had an abortion shortly before the start of pregnancy

PregID date_abort

1 mmddyy

3 mmddyy

 

What I need to do is to exclude all pregnancies (so all claims from any pregnancy) from the claims_file, which are listed in the abortion_file. 

I'm not sure how to go about this.

 

I usually run this code to ONLY include patients defined in another file, but I'm not sure how to change it, in order to EXCLUDE patients defined in another file. 

 

data claims_no abort;
set claims_file;
if _n_ = 1
then do;
declare hash a (dataset:"abortions_file");
a.definekey("pregID");
a.definedone();
end;
if a.check() = 0;
run;

 

Many thanks in advance, Julia

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @jspoend,

 

Just insert a "not" (symbol: ~) into the subsetting IF condition:

if a.check() ~= 0;

(You can also use the mnemonic ne instead of ~=.) Nonzero return codes from the CHECK method mean that the key value (here: the pregID value) was not found in the hash object (here: in the abortions_file). Missing return codes cannot occur anyway, so you can even simplify the condition to

if a.check();

This is equivalent to the requirement that the return code is neither zero nor missing.

View solution in original post

2 REPLIES 2
FreelanceReinh
Jade | Level 19

Hi @jspoend,

 

Just insert a "not" (symbol: ~) into the subsetting IF condition:

if a.check() ~= 0;

(You can also use the mnemonic ne instead of ~=.) Nonzero return codes from the CHECK method mean that the key value (here: the pregID value) was not found in the hash object (here: in the abortions_file). Missing return codes cannot occur anyway, so you can even simplify the condition to

if a.check();

This is equivalent to the requirement that the return code is neither zero nor missing.

jspoend
Obsidian | Level 7
Too simple, thank you very much!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 481 views
  • 0 likes
  • 2 in conversation