BookmarkSubscribeRSS Feed
TemenuzhkaPanayotova
Calcite | Level 5

Hello! I have the following question.

I am using SAS Enterprise Guide and I have the data structured like that:

Client ID:    Product:

1                    A

1                    B

2                    A

2                    D

2                    C

3                    B

What I am trying to do is create binary variables for every product for every customer ID so that I can built a predictive model in SAS Enterprise Miner.

I want the data to look like that:

Client ID:    Product A:        Product B:         Product C:   Product 😧

1                     1                      1                         0             0

2                      1                      0                         1             1

3                      0                      1                         0              0

The problem is that there are over 50 different products, and each client has different number of products and the ordinary functions are not working. Is there any other way to create that table with a query?

Thank

3 REPLIES 3
Ksharp
Super User

Code: Program

data have;
input ClientID   Product $;
cards;
1 A
1 B
2 A
2 D
2 C
3 B
;
run;
data have;
set have;
retain v 1;
run;
proc transpose data=have out=temp(drop=_:) prefix=Product_;
by ClientID;
var v;
id Product;
run;
proc stdize data=temp out=want missing=0 reponly;run;

TemenuzhkaPanayotova
Calcite | Level 5

Thank you! Is there a way how to do it without listing the variables and the data, because I have 50 000 rows of observations?

PGStats
Opal | Level 21

The first step in Xia's code is only there to create some example data. Use your own dataset instead. You could start with the second step as :

data have;

set myLibrary.myDataset;

retain v 1;

run;


PG

PG

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

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
  • 1113 views
  • 2 likes
  • 3 in conversation