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

Hi,

 

I have a data set which contains  product_id's and a number of booleans where each row has  a boolean set to true.

I have multiple rows with the same product_id and each row has different booleans set to true

is there a way to group these rows in to one row per product_id?

 

example 

prod_ID    bool1    bool2      bool3   bool4

A               0           0            1           0

A               0           0            0           1

B               1           0            0           0

B               0           0            0           1

 

I would like to get a date set which looks like

A              0            0             1           1

B              1            0             0           1

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

Easily done with proc summary:

data have;
input prod_ID $   bool1    bool2      bool3   bool4;
datalines;
A               0           0            1           0
A               0           0            0           1
B               1           0            0           0
B               0           0            0           1
;

proc summary data=have;
by prod_id;
var bool:;
output out=want (drop=_freq_ _type_) max()=;
run;

View solution in original post

1 REPLY 1
Kurt_Bremser
Super User

Easily done with proc summary:

data have;
input prod_ID $   bool1    bool2      bool3   bool4;
datalines;
A               0           0            1           0
A               0           0            0           1
B               1           0            0           0
B               0           0            0           1
;

proc summary data=have;
by prod_id;
var bool:;
output out=want (drop=_freq_ _type_) max()=;
run;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 382 views
  • 1 like
  • 2 in conversation