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?
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
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;
The Frequency procedure is a good way to get counts.
For example:
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
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.