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!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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