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.

 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

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
  • 640 views
  • 0 likes
  • 3 in conversation