SAS coding help

#1
Hi,

I am having trouble writing a code for this, say I have the following data:

product type
a 1
a 2
a 3
b 1
c 1
c 2
d 3
e 1
e 2
e 3

I want to make 3 data sets, 1st one only has products which has all 3 type (1, 2, 3) so that dataset will have product a and e.

2nd dataset is just products with 2 types (1 and 2) so it will have product c in it.

then last data set just has product with 1 type (product b and d)

or is there a way to add a column which gives each product row a value say z if it has 3 types and x if it has 2 types.

either way it will help me very much.
My data is very large over 55,000 rows.

Thanks !!!!
 
#2
Okay you can do it both ways depending on what you want to do later.

1. data work.setallthreetypes;
set work.original;
if variable=1 or variable=2 or variable=3;
run;

data work.settwotypes;
set work.original;
if variable=1 or variable=2;
run;

data work.setonetype;
set work.original;
if variable=1;
run;

2. data work.newvariable;
set work.original;
if variable=1 or variable=2 then newvar=x;
if variable=1 or variable=2 or variable=3 then newvar=y;
if variable=1 then newvar=z;
run;

data work.setallthreetypes;
set work.original;
if newvar=x;
run;

data work.settwotypes;
set work.original;
if newvar=y;
run;

data work.setonetype;
set work.original;
if newvar=z;
run;


Both ways do the same thing but I think the first version is more simple to follow but it depends on what is being done further down.

Hope this helps.
 
Last edited: