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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.