Help using Base SAS procedures

my error is saying my variable doesn't match the type

Reply
Contributor
Posts: 21

my error is saying my variable doesn't match the type

Hi

 

So i converted numeric variables into categorical variable.

By far when i check my temporary data called 'forreg' i can see 'Male' equals 1 for Gender.

 

But When i tried to plot PROC REG it still doesn't allow me to plot

and gives me error, saying:

 

150 data forreg;
151 set new;
152 KEEP Exam Assign Gender;
153 IF Gender='Male' then Gender=1; Else Gender=0;
154 run;

NOTE: Numeric values have been converted to character values at the places given by: (Line)Smiley SadColumn).
153:30 153:45
NOTE: There were 146 observations read from the data set WORK.NEW.
NOTE: The data set WORK.FORREG has 146 observations and 3 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds


155
156 TITLE1 'Scatter';
157 PROC REG data=forreg;
158 MODEL Exam = Assign Gender /VIF;
ERROR: Variable GENDER in list does not match type prescribed for this list.
NOTE: The previous statement has been deleted.
159 RUN;

WARNING: No variables specified for an SSCP matrix. Execution terminating.
NOTE: PROCEDURE REG used (Total process time):
real time 0.08 seconds
cpu time 0.03 seconds

 

How can i plot PROC REG, using my converted dummy variables?

 

And here is my code

data forreg;
  set new;
  KEEP Exam Assign Gender;
IF Gender='Male' then Gender=1; Else Gender=0;
run;

TITLE1 'Scatter';
PROC REG data=forreg;
MODEL  Exam = Assign Gender /VIF;
RUN;

Super User
Posts: 6,781

Re: my error is saying my variable doesn't match the type

Once a variable is character, it never changes to become numeric.  As the note in your log indicated, GENDER is still character after these statements:

 

if gender='Male' then gender=1; else gender=0;

 

It would be easy enough for you to verify that result by running a PROC CONTENTS on the result.

 

You can create a new variable:

 

if gender='Male' then gender_num=1; else gender_num=0;

 

You can even end up with a numeric variable named GENDER:

 

drop gender;

rename gender_num=gender;

 

But the original GENDER variable remains character for the duration of its existence.

Ask a Question
Discussion stats
  • 1 reply
  • 289 views
  • 2 likes
  • 2 in conversation