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

Hi everyone,

 

I'm trying to count the number of females in each country and group it by country in my data set. I've posted my code thus far but am not getting far. 

 

proc sql;
create table gender_dispurtion as
select gender, country,
	if gender = 'F' then
		count(*) label = '#_females'
	end
from customer_1
group by country
order by country;
quit;

38 if gender = 'F' then
------ -
1 22
200
WARNING 1-322: Assuming the symbol GE was misspelled as gender.

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string,
a numeric constant, a datetime constant, a missing value, (, +, -, ALL, ANY, BTRIM,
CALCULATED, CASE, INPUT, PUT, SELECT, SOME, SUBSTRING, TRANSLATE, USER.

ERROR 200-322: The symbol is not recognized and will be ignored.

39 count(*) label = '#_females'
40 end
---
22
ERROR 22-322: Syntax error, expecting one of the following: ',', AS.

 

I've attached my data set in excel because it does not allow me to attach SAS data tables for some reason.

 

Any help would be appreciated.

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

proc sql doesn't support if then statements. I think you are looking for something like (untested):

 

proc sql;
  create table gender_dispurtion as
    select  country, count(*) as females
      from customer_1 (where=(gender eq 'F'))
        group by country
          order by country
  ;
quit;

Art, CEO, AnalystFinder.com

View solution in original post

4 REPLIES 4
art297
Opal | Level 21

proc sql doesn't support if then statements. I think you are looking for something like (untested):

 

proc sql;
  create table gender_dispurtion as
    select  country, count(*) as females
      from customer_1 (where=(gender eq 'F'))
        group by country
          order by country
  ;
quit;

Art, CEO, AnalystFinder.com

Scott86
Obsidian | Level 7

Thanks everyone 🙂

lakshmi_74
Quartz | Level 8
proc sql;
create table gender_dispurtion as
Select count(gender),country from customer_1 where upcase(gender) eq 'F'
group by country;
quit;
Reeza
Super User

I would suggest PROC FREQ

 

PROC FREQ data = customer_1;

table country*gender  / out= summary_by_gender;

run;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 4 replies
  • 2850 views
  • 3 likes
  • 4 in conversation