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

Hello!

 

I have a dataset with multiple entries per ID, and would like to condense to a single entry per ID, which shows is any of the entries were positive for a given variable.

 

Eg

What I have:

ID         A          B

1          0          0

1          1          0

1          0          0

2          1          1

2          0          0

2          0          0

3          0          0

3          0          0

3          0          0

 

What I want:

ID         Any_A  Any_B

1          1          0

2          1          1

3          0          0

 

 

Many thanks

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

I think you may be looking for:

 

proc summary data=have nway;
   class Id;
   var A B;
   output out=want (drop=_type_ _freq_) max=Any_A Any_B;
run;

The NWAY option requests only the greatest value of the _type_ variable which indicates the specific variables on the CLASS statement are used for specific output. The default behavior for Proc Summary is to provide a summary overall of all values plus combinations of variables appearing on the Class statement.

The Drop removes variables not requested that would indicate the combination and count of per combination in the _freq_. the MAX statistic will keep the 1 if present and the = indicates the names of the output variable(s) for the statistics requested.

 

View solution in original post

2 REPLIES 2
Tom
Super User Tom
Super User

To find if ANY are TRUE then take the MAX().

 

You can use PROC SUMMARY.

proc summary data=have;
  by id;
  var a b ;
  output out=want max= ;
run;
ballardw
Super User

I think you may be looking for:

 

proc summary data=have nway;
   class Id;
   var A B;
   output out=want (drop=_type_ _freq_) max=Any_A Any_B;
run;

The NWAY option requests only the greatest value of the _type_ variable which indicates the specific variables on the CLASS statement are used for specific output. The default behavior for Proc Summary is to provide a summary overall of all values plus combinations of variables appearing on the Class statement.

The Drop removes variables not requested that would indicate the combination and count of per combination in the _freq_. the MAX statistic will keep the 1 if present and the = indicates the names of the output variable(s) for the statistics requested.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 231 views
  • 0 likes
  • 3 in conversation