BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
sasgorilla
Pyrite | Level 9

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!

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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;

View solution in original post

2 REPLIES 2
s_lassen
Meteorite | Level 14

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;
sasgorilla
Pyrite | Level 9

Got it. That worked, thanks! I was thinking there was a statement within proc print but good to know a data step was needed. 

 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 869 views
  • 1 like
  • 2 in conversation