Hi Dears,
I would greatly appreciate your help to delete some matched observations from a dataset. Briefly, I have a dataset in which cases are matched with controls and then a variable (exclusion_variable) is used to exclude ID that met the criterion of exclusion. As presented in the table below, I would like to delete the corresponding controls as the case (ID=1x) is to be excluded.
ID matching_ID case exclusion_variable
1x aa 1 1
2x aa 0 0
3x aa 0 0
Thank you very match for your valuable help!
Why do your refer BOTH to variable CASE and variable EXCLUSION_VAR? Do you just mean to filter out all matching_id's for which any record has an EXCLUSION_VAR=1?
Edited addition:
If so, then this will do:
data have;
input id :$2. matching_id :$2. case exclusion_variable;
datalines;
1x aa 1 1
2x aa 0 0
3x aa 0 0
4X bb 0 0
run;
data want (drop=rc);
set have;
if _n_=1 then do;
declare hash exclude_id (dataset:'have (keep=matching_id exclusion_variable where=(exclusion_variable=1))');
exclude_id.definekey('matching_id');
exclude_id.definedone();
end;
rc=exclude_id.check();
if rc^=0;
run;
@arzon welcome to the SAS forums.
Unfortunately your question is unclear. Can you please clarify what you have and what you want as output?
@arzon wrote:
Hi Dears,
I would greatly appreciate your help to delete some matched observations from a dataset. Briefly, I have a dataset in which cases are matched with controls and then a variable (exclusion_variable) is used to exclude ID that met the criterion of exclusion. As presented in the table below, I would like to delete the corresponding controls as the case (ID=1x) is to be excluded.
ID matching_ID case exclusion_variable
1x aa 1 1
2x aa 0 0
3x aa 0 0
Thank you very match for your valuable help!
Hi Reeza,
Thanks for your reply and sorry for being unclear (I am not fully fluent in English and that may explain why)
To clarify, lets consider the 'exclusion_variable' as 'death' and that the ID=1x is dead (case=1) and is to be excluded from the dataset (if death=1 then delete). As the ID 2x, and 3x are matched to the ID 1x (i.e. same matching_ID) I would like to delete these ID from the dataset to preserve the matching nature of the overall dataset. So, How can I can suppress these matched ID?
Hope this clarifies.
Thank you very much
So based on your sample data what do you expect as output?
ID matching_ID case exclusion_variable
1x aa 1 1
2x aa 0 0
3x aa 0 0
4x bb 1 0
5x bb 0 0
6x bb 0 0
From the above table, my output will be:
ID matching_ID case exclusion_variable
4x bb 1 0
5x bb 0 0
6x bb 0 0
Why do your refer BOTH to variable CASE and variable EXCLUSION_VAR? Do you just mean to filter out all matching_id's for which any record has an EXCLUSION_VAR=1?
Edited addition:
If so, then this will do:
data have;
input id :$2. matching_id :$2. case exclusion_variable;
datalines;
1x aa 1 1
2x aa 0 0
3x aa 0 0
4X bb 0 0
run;
data want (drop=rc);
set have;
if _n_=1 then do;
declare hash exclude_id (dataset:'have (keep=matching_id exclusion_variable where=(exclusion_variable=1))');
exclude_id.definekey('matching_id');
exclude_id.definedone();
end;
rc=exclude_id.check();
if rc^=0;
run;
Hi mkeintz,
You exactly provided the solution to my query.
Thank you very much for your support.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.