I wish to convert a of the form below
table
Color Style
A1 B1
A1 B5
A5 B2
A3 B3
A2 B1
A2 B2
A4 B1
A1 B3
A5 B1
A3 B4
A4 B4
A5 B2
A4 B2
A4 B5
A1 B2
A3 B1
A5 B1
A2 B3
A4 B2
A3 B2
A5 B3
A2 B3
A4 B3
A1 B4
A2 B5
into a contingency table and extract the frequecies into the form of table [ii] below.
Could you please direct me to any material that could help me do this?
"color" "Style" "Count"
"A1" "B1" 4
"A1" "B2" 2
"A1" "B3" 4
"A1" "B4" 1
"A1" "B5" 6
"A2" "B1" 1
"A2" "B2" 3
"A2" "B3" 2
"A2" "B4" 0
"A2" "B5" 4
"A3" "B1" 3
"A3" "B2" 3
"A3" "B3" 1
"A3" "B4" 5
Tell me if you realy need those precise headers, otherwise, you could use this:
data have;
input color $ style $;
datalines;
A1 B1
A1 B5
A5 B2
A3 B3
A2 B1
A2 B2
A4 B1
A1 B3
A5 B1
A3 B4
A4 B4
A5 B2
A4 B2
A4 B5
A1 B2
A3 B1
A5 B1
A2 B3
A4 B2
A3 B2
A5 B3
A2 B3
A4 B3
A1 B4
A2 B5
;
proc sql;
create table want as
select quote(trim(color)) as qcolor label="color", quote(trim(style)) as qstyle label="Style",
count(*) as count from have
group by calculated qcolor, calculated qstyle;
select * from want;
quit;
PG
Hi PGStats, Thanks!
Could the expected frequecies have been calculated and extracted similarly?
Yes they could. But it would be a lot simpler to use proc freq to get those.
PG
As PG mentioned Proc Freq is more efficient.
proc freq data=have;
tables color*style/out=want expected;
run;
Oops...The expected should be outexpect instead.
Thanks, PGStats and Reeza. Is there a way of determining which combinations had zero count as part of proc freq?
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.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.