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;

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!

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.

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