BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ZZ_Zheng
Calcite | Level 5

Hi, I have a 6700 person sample size with 9 binary (0 or 1) variables, I want to see the most common (maybe top 20) combinations of these 2^9 possible combinations since most combinations will have 0 or 1 observation. In other words, I want to sort the proc tabulate output by "sum" or "n". I also create a variable called x, which equal 1 for every observation.

 

Below are my code and SAS output 

proc tabulate data=paper order=freq;
class structural_flag social_support_flag behaviors_flag bills_flag housing_flag mental_health_flag resources_flag jail_flag food_cat;
var x;
table structural_flag*social_support_flag*behaviors_flag*bills_flag*housing_flag*mental_health_flag*resources_flag*jail_flag*food_cat,
	(x)*(Sum colpctn);run;

WeChat Image_20190304162915.png 

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

How about

 

proc sql outobs=20;
create table paperTable from
select structural_flag, social_support_flag, behaviors_flag, bills_flag, housing_flag, 
    mental_health_flag, resources_flag, jail_flag, food_cat, count(*) as nn 
from paper
group by structural_flag, social_support_flag, behaviors_flag, bills_flag, housing_flag, 
    mental_health_flag, resources_flag, jail_flag, food_cat
order by nn desc;
quit;

proc tabulate data=paperTable order=data;
class structural_flag social_support_flag behaviors_flag bills_flag housing_flag mental_health_flag 
    resources_flag jail_flag food_cat;
var nn;
table structural_flag*social_support_flag*behaviors_flag*bills_flag*housing_flag*mental_health_flag*
    resources_flag*jail_flag*food_cat,
	nn*(Min colpctsum);
run;

(untested)

PG

View solution in original post

2 REPLIES 2
PGStats
Opal | Level 21

How about

 

proc sql outobs=20;
create table paperTable from
select structural_flag, social_support_flag, behaviors_flag, bills_flag, housing_flag, 
    mental_health_flag, resources_flag, jail_flag, food_cat, count(*) as nn 
from paper
group by structural_flag, social_support_flag, behaviors_flag, bills_flag, housing_flag, 
    mental_health_flag, resources_flag, jail_flag, food_cat
order by nn desc;
quit;

proc tabulate data=paperTable order=data;
class structural_flag social_support_flag behaviors_flag bills_flag housing_flag mental_health_flag 
    resources_flag jail_flag food_cat;
var nn;
table structural_flag*social_support_flag*behaviors_flag*bills_flag*housing_flag*mental_health_flag*
    resources_flag*jail_flag*food_cat,
	nn*(Min colpctsum);
run;

(untested)

PG
ZZ_Zheng
Calcite | Level 5

Thanks! PG Stats. It works well!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 2 replies
  • 1176 views
  • 0 likes
  • 2 in conversation