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
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.
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.
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!
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.