BookmarkSubscribeRSS Feed
EMKBB
Calcite | Level 5

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

6 REPLIES 6
PGStats
Opal | Level 21

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

PG
EMKBB
Calcite | Level 5

Hi  PGStats, Thanks!

EMKBB
Calcite | Level 5

Could the expected frequecies have been calculated and extracted similarly?

PGStats
Opal | Level 21

Yes they could. But it would be a lot simpler to use proc freq to get those.

PG

PG
Reeza
Super User

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.

EMKBB
Calcite | Level 5

Thanks, PGStats and Reeza. Is there a way of determining which combinations had zero count as part of proc freq?

sas-innovate-2024.png

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.

 

Register now!

What is Bayesian Analysis?

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 940 views
  • 0 likes
  • 3 in conversation