BookmarkSubscribeRSS Feed
ChloeNguyen
Calcite | Level 5

I want to find how many observations are by customer type in different place. This is the dataset:

Place     Customer's name          Customer type

IL             Alex                                Gold

FL            Mike                               Gold

IL            Mie                                  Gold

IL            Prince                              Silver

FL           Troy                                 Silver

 

For example, I want to count how many observations are by "Gold" customer type in IL and FL?

4 REPLIES 4
CurtisMackWSIPP
Lapis Lazuli | Level 10

Something like this?

 

 

data have;
  infile datalines dsd;
  input Place $ Customer $ Type $;
datalines;
IL,Alex,Gold
FL,Mike,Gold
IL,Mie,Gold
IL,Prince,Silver
FL,Troy,Silver
run;

proc sql;
  create table want as
  select Place,Type,count(*) as count
  from have
  group by Place,Type;
quit;

I

 

CurtisMackWSIPP
Lapis Lazuli | Level 10

If you want them as column variables use this.

 

proc transpose data=want out=want_t(drop = _name_);
  by Place;
  var Count;
  id type;
run;
jimbarbour
Meteorite | Level 14

The Frequency procedure is a good way to get counts.

 

For example:

jimbarbour_0-1600915704337.png

 

Which was produced by the following code:

ODS	NOPROCTITLE;

DATA	Cust_Data;
	INPUT	Place    		:	$CHAR2. 
			Customer_name	:	$CHAR12.
			Customer_type	:	$CHAR12.
			;
datalines;
IL             Alex                                Gold
FL            Mike                               Gold
IL            Mie                                  Gold
IL            Prince                              Silver
FL           Troy                                 Silver
;;;;
RUN;

PROC	FREQ	DATA=Cust_Data;
	TABLES	PLACE*Customer_Type	/	NOROW	NOCUM	NOPERCENT	NOCOL;
RUN;

Jim

andreas_lds
Jade | Level 19

Even proc summary can do this:

proc summary data=have nway;
  class Place CustomerType;
  output out=want(drop=_type_ rename=(_freq_=count));
run;

or proc tabulate:

proc tabulate data=have;
  class CustomerType Place;
  table Place, CustomerType*n;
run;