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.
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!
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.
Ready to level-up your skills? Choose your own adventure.