BookmarkSubscribeRSS Feed
Mimo
Calcite | Level 5
I am using SAS for the first time.

My input data is:
input personid annualearnings sex $ schooling ftwe populationmunicipality;
cards;
1 55000 male 12 10 88000
2 67000 male 16 8 66000
......etc.

This is working fine. But I'm trying to calculate the mean, standard deviation, and standard error of the mean for earnings, a female binary variable, schooling, experience (ftwe), and a rural binary variable (a rural area is one where fewer than 10,000 people reside); then repeat this, but by sex (for all the other variables in this list).

When I set my first binary variable (sex = female) I have no problem running it. But if I try adding a second binary variable for population municipality, I don't know how to do it as I keep receiving error messages (see below). Am I defining it the wrong way? I have tried several different methods, but I am not sure what to do next.... Help? Thanks!!!

data out.permanent(keep = annualearnings log_annualearnings female schooling ftwe populationmunicipality);
set temp(drop = personid);

where (annualearnings^=. and sex^=" " and schooling^=. and ftwe^=. and populationmunicipality^=.);

log_annualearnings=log(annualearnings);

if sex="female" then female=1;
else if sex="male" then female=0;

if populationmunicipality LT 10000, then group='rural';
else group='urban'

run;
4 REPLIES 4
Reeza
Super User
You've got some syntax errors in your last two lines:

if populationmunicipality LT 10000, then group='rural';
else group='urban'

An extra comma and no semicolon after the last line.

You should look up proc means though, using by groups specifically. You don't necessarily have to recode your text categories into binary variables in SAS.
ieva
Pyrite | Level 9
And one more, "=" sign missing in that line.

Should be:

if populationmunicipality LT= 10000 then group='rural';
else group='urban';
DBailey
Lapis Lazuli | Level 10
Isn't LE the accepted mnemonic for "less than or equal to" rather than "LT="?
ballardw
Super User
If you are going to make lots of dichotomous 1/0 variables the following may help.

Female = (Sex = 'female');

Though I would probably write:

Female = (Upcase(Sex) = 'FEMALE');

SAS treats "true" responses as 1 and false as 0.

Care needs to be taken with this approach and LT or LE comparisons as missing values will be true as missing is the smallest "value" SAS understands.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 872 views
  • 0 likes
  • 5 in conversation