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?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.