I created a flag variable where there were duplicate observations.
To examine these further, I want to print all observations for IDs that had a flag, not just the particular ones that were flagged. The below code obviously only prints observations with a flag value.
proc print data=a;
where flag>0;
run;
How can I print all observations for IDs with flags? So for the below, I would want all observations of ID 1 and 3 to be printed since they had a flag value in any of the observations.
data a;
input id var1 flag;
datalines;
1 1 0
1 1 1
2 3 0
2 2 0
3 1 0
3 2 0
3 1 1
;
run;
Thank you!
You can do it like this (data must be sorted by ID, like your sample data):
data want;
merge a(keep=id flag where=(flag>0) in=ok) a;
by id;
if ok;
run;
You can do it like this (data must be sorted by ID, like your sample data):
data want;
merge a(keep=id flag where=(flag>0) in=ok) a;
by id;
if ok;
run;
Got it. That worked, thanks! I was thinking there was a statement within proc print but good to know a data step was needed.
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.