Help using Base SAS procedures

Question with SAS comparison operators

Reply
N/A
Posts: 1

Question with SAS comparison operators

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;
Super User
Posts: 17,912

Re: Question with SAS comparison operators

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.
Frequent Contributor
Posts: 82

Re: Question with SAS comparison operators

And one more, "=" sign missing in that line.

Should be:

if populationmunicipality LT= 10000 then group='rural';
else group='urban';
Super Contributor
Posts: 578

Re: Question with SAS comparison operators

Isn't LE the accepted mnemonic for "less than or equal to" rather than "LT="?
Super User
Posts: 10,538

Re: Question with SAS comparison operators

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.
Ask a Question
Discussion stats
  • 4 replies
  • 174 views
  • 0 likes
  • 5 in conversation