BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
woroyire
Calcite | Level 5

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.

Thanks for your help.

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;

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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.'

View solution in original post

5 REPLIES 5
Patrick
Opal | Level 21

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.'

woroyire
Calcite | Level 5

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.

woroyire
Calcite | Level 5

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

Thank you so much!

stat_sas
Ammonite | Level 13

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

Reeza
Super User

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

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
  • 5 replies
  • 845 views
  • 3 likes
  • 4 in conversation