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

sas-innovate-2024.png

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.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 3 replies
  • 848 views
  • 6 likes
  • 3 in conversation