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;
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.'
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.'
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.
Patrick, I am sorry, your suggestion worked. I just needed to fix another mistake to be able to realize it.
Thank you so much!
Also, I think in proc reg DUMMIES data set will be used instead of FINAL.
You can also look into the CLASS statement in some other procs as well, they automatically create categorical variables for you.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.