I have two datasets:
DATA List_ID;
INPUT ID;
DATALINES;
1
2
3
4
;
DATA Flag_ID;
INPUT ID1 ID2;
DATALINES;
1, 5
2, 3
6, 4
;
I am trying to create a flag if the IDs in Flag_ID appear in List_ID, adding two new columns to Flag_ID (FlagID1 FLAGID2). I used hash table to do this when flagging one ID variable, with the same name:
data FlagOne;
if _N_ = 1 then do;
declare hash TST(dataset: "List_ID");
TST.definekey("id1"); /*Pretending the ID variable is ID1 to match the other variable */
TST.definedone();
end;
set Flag_ID
ID1_Flag= (TST.check() = 0);
run;
How can I do a similar operation using two variables and creating two new flags? My desired output is:
ID1 ID2 FlagID1 FlagID2
1 5 1 0
2 3 1 1
6 4 0 1
You need to use the key: argument to the check method:
data FlagOne;
if _N_ = 1 then do;
declare hash TST(dataset: "List_ID");
TST.definekey("id");
TST.definedone();
end;
set Flag_ID;
ID1_Flag = (TST.check(key:ID1) = 0);
ID2_Flag = (TST.check(key:ID2) = 0);
run;
You need to use the key: argument to the check method:
data FlagOne;
if _N_ = 1 then do;
declare hash TST(dataset: "List_ID");
TST.definekey("id");
TST.definedone();
end;
set Flag_ID;
ID1_Flag = (TST.check(key:ID1) = 0);
ID2_Flag = (TST.check(key:ID2) = 0);
run;
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.