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
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
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
Thanks everyone 🙂
I would suggest PROC FREQ
PROC FREQ data = customer_1;
table country*gender / out= summary_by_gender;
run;
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.
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.