Solved
New Contributor
Posts: 3

# question sas program.

My assignment consist of creating dummies variables for sex and age and using them in a multiple regression procedure: Here is what I did. I need help finding out why

DUMMIES FOR AGE VARIABLES PRINT ONLY ZEROS.

My goal is to do a regression analysis using dummy variables for sex and age my attempt is at the end of the program.

The procedure does not work, I believe it is because of a problem with the dummy variables.

DATA REGRESS;

DO AGE = '6 Mo.','9 Mo.','12 Mo.';

DO SEX = 'M','F';

DO I = 1 to 7;

SPEED = INT(RANNOR(451212)*5 + 20 + 4*(AGE EQ '9 Mo.')

+ 5*(AGE EQ '12 Mo.') - 8*(SEX EQ 'M'));

Rest_Time = INT(RANUNI(451212)*15 + 200 + 4*(AGE EQ '6 Mo.')

+ 5*(AGE EQ '9 Mo.') - 8*(SEX EQ 'F'));

Recovery = INT(RANNOR(451212)*5 + 125 + 4*(AGE EQ '9 Mo.')

+ 5*(AGE EQ '12 Mo.') - 8*(SEX EQ 'M'));

OUTPUT;

END;

END;

END;

DROP I;

RUN;

***** part of the program I need help with starts here***

DATA DUMMIES;

SET REGRESS;

IF AGE= '6 MO.' THEN AGE1=1; ELSE AGE1=0;

IF AGE ='9 MO.' THEN AGE2=1; ELSE AGE2=0;

IF SEX ='F' THEN FEMALE=1; ELSE FEMALE=0;

PROC PRINT DATA=DUMMIES;

VAR AGE1 AGE2 FEMALE;

RUN;

PROC REG DATA = FINAL;

TITLE' REGRESSION WITH SPEED AS DEPENDENT VARIABLE';

MODEL SPEED = AGE1 AGE2 FEMALE REST_TIME RECOVERY/P R;

RUN;

QUIT;

Accepted Solutions
Solution
‎12-16-2014 10:21 PM
Posts: 4,742

## Re: question with creating dummy variables.

String comparisons like IF AGE= '6 MO.' are case sensitive.

When you populate the variables you're using mixed case:  DO AGE = '6 Mo.','9 Mo.','12 Mo.';

You will get around this by "upcasing" the age variable before the comparison: IF upcase(AGE)= '6 MO.'

All Replies
Solution
‎12-16-2014 10:21 PM
Posts: 4,742

## Re: question with creating dummy variables.

String comparisons like IF AGE= '6 MO.' are case sensitive.

When you populate the variables you're using mixed case:  DO AGE = '6 Mo.','9 Mo.','12 Mo.';

You will get around this by "upcasing" the age variable before the comparison: IF upcase(AGE)= '6 MO.'

New Contributor
Posts: 3

## Re: question with creating dummy variables.

Thank you Patrick and stat@sas. I change the strings to uppercase with no success. What puzzles me is that the variable SEX responds as wanted with 0s and 1s.

New Contributor
Posts: 3

## Re: question with creating dummy variables.

Patrick, I am sorry, your suggestion worked. I just needed to fix another mistake to be able to realize it.

Thank you so much!

Posts: 1,270

## Re: question with creating dummy variables.

Also, I think in proc reg DUMMIES data set will be used instead of FINAL.

Super User
Posts: 23,776

## Re: question with creating dummy variables.

You can also look into the CLASS statement in some other procs as well, they automatically create categorical variables for you.

🔒 This topic is solved and locked.