Help using Base SAS procedures

Creating dummy variable

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Creating dummy variable

Hi there,

 

I want to create a dummy variable for gender (m=0, f=1) so that I can use proc reg for a bivariate analyses. However, my error keeps indicating that my variable doesn't exist. Any insight would be useful Smiley Happy

 


data eva.cohort;
set eva.finalcohort;

if sex="m" then sexm=0;

if sex="f" then sexf=1;
avgvol1=sum(avg_2009+avg_2011+avg_2012+avg_2014)/4;
avgvol2=sum(bee_avg_2009+bee_avg_2011+bee_avg_2012+bee_avg_2014)/4;
run;

 

proc means data=eva.cohort n nmiss mean median max min;

var avgvol1 avgvol2;

run;

 

proc reg data=eva.cohort;

model avgvol1=sexm sexf;

run;

 


Accepted Solutions
Solution
‎03-24-2018 01:45 PM
Super User
Posts: 6,785

Re: Creating dummy variable

Perhaps your actual data doesn't contain "m" and "f".  Perhaps it contains "M" and "F" instead.

 

At any rate, you would be well advised to treat SEX as a CLASS variable within PROC REG.  Most regression procedures will automatically create the proper dummy variables when you use a CLASS statement.

 

Note for the future:  instead of posting the program, post the log so we can see what message applies to what step.

View solution in original post


All Replies
Solution
‎03-24-2018 01:45 PM
Super User
Posts: 6,785

Re: Creating dummy variable

Perhaps your actual data doesn't contain "m" and "f".  Perhaps it contains "M" and "F" instead.

 

At any rate, you would be well advised to treat SEX as a CLASS variable within PROC REG.  Most regression procedures will automatically create the proper dummy variables when you use a CLASS statement.

 

Note for the future:  instead of posting the program, post the log so we can see what message applies to what step.

Respected Advisor
Posts: 3,055

Re: Creating dummy variable

Posted in reply to Astounding

@Astounding wrote:

 

At any rate, you would be well advised to treat SEX as a CLASS variable within PROC REG.  Most regression procedures will automatically create the proper dummy variables when you use a CLASS statement.


PROC GLM, not PROC REG

 

To @kthartma: there is no need to create your own dummy variables. PROC GLM will create them for you, and also avoid the programming error you are having. 

--
Paige Miller
Occasional Contributor
Posts: 10

Re: Creating dummy variable

Posted in reply to Astounding

Thanks so much! I ended up using proc glm. 

Super User
Posts: 23,771

Re: Creating dummy variable

You're not using the SUM() function as usually intended either. 

It's usually used when you want to consider missing as 0, this approach wouldn't do that because you've listed the items with + in between rather than comma's. 

Test your code with the following:

 

 

avgvol1=sum(avg_2009+avg_2011+avg_2012+avg_2014)/4;

avgvol1_check0 =sum(avg_2009, avg_2011, avg_2012, avg_2014)/4;
avgvol1_check1 = sum(of avg_2009-avg_2014)/ 4;
avgvol1_check2 = mean(of avg_2009-avg_2014);

 

If you have different results between any of the calculations you have an issue. 

Esteemed Advisor
Posts: 5,539

Re: Creating dummy variable

If you insist on using proc reg your code should read:

 

data eva.cohort;
set eva.finalcohort;

if sex="m" then sexDum=0;
if sex="f" then sexDum=1;

avgvol1 = (avg_2009 + avg_2011 + avg_2012 + avg_2014) / 4;
avgvol2 = (bee_avg_2009 + bee_avg_2011 + bee_avg_2012 + bee_avg_2014) / 4;
run;

proc means data=eva.cohort n nmiss mean median max min;
var avgvol1 avgvol2;
run;

proc reg data=eva.cohort;
model avgvol1 = sexDum;
run;
PG
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 295 views
  • 3 likes
  • 5 in conversation