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

  A product can have three categories 'X','Y','Z'.
   Now if a customer has all three product X,Y,Z or X Y or X Z then he should be categorized as having X
     if he has Y or Z then he shouuld be categorized as Y
       if only Z then categoried as having only Z
      
Customer    product     category
A                      X            X
A                      Y        
A                      Z
B                      Y            Y
B                      Z
C                     X            X
C                     Z       
D                     Z            Z

1 ACCEPTED SOLUTION

Accepted Solutions
Steelers_In_DC
Barite | Level 11

I think this is what you are looking for but without a question it's hard to tell:

data have;

infile cards dsd;

input Customer $ product $;

cards;

A,X

A,Y

A,Z

B,Y

B,Z

C,X

C,Z

D,Z

;

run;

proc sql;

create table want as

select *,min(product) as category

from have

group by customer;

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

What is your question?

--
Paige Miller
Jagadishkatam
Amethyst | Level 16

Please try

data have;

input Customer$    product$     ;

cards;

A                      X    

A                      Y    

A                      Z

B                      Y    

B                      Z

C                     X     

C                     Z     

D                     Z     

;

proc transpose data=have out=want;

by customer;

var product;

run;

data want2;

merge have want;

by customer;

if first.customer and cats(of col:) in ('XYZ','XY','XZ') then category='X';

if first.customer and cats(of col:)='YZ' then category='Y';

if first.customer and cats(of col:)='Z' then category='Z';

drop _name_ col:;

run;

Thanks,

Jag

Thanks,
Jag
Steelers_In_DC
Barite | Level 11

I think this is what you are looking for but without a question it's hard to tell:

data have;

infile cards dsd;

input Customer $ product $;

cards;

A,X

A,Y

A,Z

B,Y

B,Z

C,X

C,Z

D,Z

;

run;

proc sql;

create table want as

select *,min(product) as category

from have

group by customer;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 3 replies
  • 937 views
  • 5 likes
  • 4 in conversation