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

I have a table that provides multiple customer records with multiple flags (1,0) for product items, however only 1 flag is present per record. I'd like to create a single record with the customer id and all of the product flags

Have:

Customer IDBananasApplesCherriesOranges
1231000
1230100
1230001

 

Want:

1231101
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
    class customerID;
    var bananas apples cherries oranges;
    output out=want max=;
run;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
    class customerID;
    var bananas apples cherries oranges;
    output out=want max=;
run;
--
Paige Miller
ballardw
Super User

May want to learn to search the forum.

 

I think we get this, or a very similar question, about every 4 months (possibly related to some professor's teaching schedule)

 

I will say that your desired result does not show "all the flags" because it doesn't show the 0 value "flags". Rephrasing to "I want the maximum value as the 1 valued flags indicates something of interest and 0 otherwise"  is more precise and leads to coding solutions like @PaigeMiller 

 

You also don't need to create a data set to get than information. The Procedures Report and Tabulate will show that result.

proc tabulate data=have;
   class customerid;
   var apples bananas cherries oranges;
   table customerid,
         (apples bananas cherries oranges)*max=''
         ;
run;

Proc report data=have;
   columns customerid apples bananas cherries oranges;
   define customerid/group;
   define apples/ max;
   define bananas / max;
   define cherries/ max;
   define oranges / max;
run;

For some things you may even find in handier to reshape the data so that you have a  variable "Fruit" that has values like  "Apple" "Banana" "Cherry" and "Orange".

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 302 views
  • 1 like
  • 3 in conversation