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

Hi, suppose if I have a dataset, that looks like the one below:

IDAgeGender
10M
22F
35F
44F
51M
64M
71M
81F
92F
102M
112M
123F
134M
145M
156F

The proc-freq output for Age * Gender is below:

AgeFM
010
112
222
310
412
511
610

I want to modify the proc freq step so that:

1. It exclude rows (i.e. age) where either male or female has a count of 1 or less, so that the proc freq will look as below:

AgeFM
522

2. AFTER excluding rows where counts <= 1, then it outputs the row percentages using PCT_ROW.

Is there any way I can do that in proc freq?

Thanks very much!

1 ACCEPTED SOLUTION

Accepted Solutions
Murray_Court
Quartz | Level 8

SQL is your friend here.

Pro sql;

create table want as select

age, sum(case when gender="M" then 1 else 0 end) as M,  sum(case when gender="F" then 1 else 0 end) as F

from have

group by age

having (M ge 1 or F ge 1)

;

quit;

Apologies for possible syntax errors as I am at home.

View solution in original post

3 REPLIES 3
Murray_Court
Quartz | Level 8

SQL is your friend here.

Pro sql;

create table want as select

age, sum(case when gender="M" then 1 else 0 end) as M,  sum(case when gender="F" then 1 else 0 end) as F

from have

group by age

having (M ge 1 or F ge 1)

;

quit;

Apologies for possible syntax errors as I am at home.

TomKari
Onyx | Level 15

If you're looking for an all-EG Task solution, you can use Summary Statistics to create a summary of all the data (in effect, your first table), use a Query to eliminate the rows you don't want, and then Summary Tables to present the results and percentage.

Tom

howdelicious
Fluorite | Level 6

Thanks for the help! I tried both methods and they both worked Smiley Happy For my purposes i am using a proc sql, but E.G. task solution is pretty neat too

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1550 views
  • 6 likes
  • 3 in conversation