BookmarkSubscribeRSS Feed
dfamu1989
Calcite | Level 5

1229 proc corr data = yrbs2017;

1230 var age raceeth sex grade cigarette vaping;

ERROR: Variable RACEETH in list does not match type prescribed for this list.

1231 run;

 

Getting this error message when using
YRBS Data trying to code for Race/Ethnicity

11 REPLIES 11
PGStats
Opal | Level 21

Variable RACEETH must be character. You will need to convert it to a number, otherwise it can't be involved in correlation calculations.

PG
dfamu1989
Calcite | Level 5

race=" ";

if raceeth = "Am Indian/ Alaska Native" and raceeth ="Asian" and raceeth

="Native Hawaiian/other Pl" and raceeth ="Multiple-Non-Hispanic"

and raceeth= " Multiple - Hispanic" then race = "1";

if Raceeth = "White" then race = "2";

if Raceeth= "Black" then race= "3";

 

/* 1= other, 2=White, 3=black*/

 

 

(This is how I Have it coded)

Shmuel
Garnet | Level 18

use variable race instead raceet  in proc corr.

dfamu1989
Calcite | Level 5

When I replace it race I still got a error message.

603 proc corr data = yrbs2017;

604 var age race sex grade cigarette vaping;

ERROR: Variable race in list does not match type prescribed for this list.

605 run;

dfamu1989
Calcite | Level 5
How do you convert a character to a number
dfamu1989
Calcite | Level 5

data yrbs2017;

set DATAOUT.YRBS2017;

Sex=.;

if Q2=1 then sex=1;

if Q2=2 then sex=0;

 

/* 1=female, 2=male*/

race=" ";

if raceeth = "Am Indian/ Alaska Native" and raceeth ="Asian" and raceeth

="Native Hawaiian/other Pl" and raceeth ="Multiple-Non-Hispanic"

and raceeth= " Multiple - Hispanic" then race = "1";

if Raceeth = "White" then race = "2";

if Raceeth= "Black" then race= "3";

 

/* 1= other, 2=White, 3=black*/

age=.;

if Q1=1 then age=1;

if Q1=2 then age=2;

if Q1=3 then age=3;

if Q1=4 then age=4;

if Q1=5 then age=5;

if Q1=6 then age=6;

if Q1=7 then age=7;

grade=.;

if Q3=1 then grade=1;

if Q3=2 then grade=2;

if Q3=3 then grade=3;

if Q3=4 then grade=4;

cigarette=.;

if Q30=1 then cigarette=0;

if Q30=2 then cigarette=1;

 

/* 0=cigarette use, 1=no cigarette use*/

vaping=.;

if Q34=1 then vaping=0;

if Q34=2 then vaping=1;run;

 

/* 0=vaping, 1=no vaping*/

proc freq data=yrbs2017;

tables age raceeth sex grade cigarette vaping;

run;

proc freq data=yrbs2017;

tables vaping* age/ chisq;

run;

proc freq data=yrbs2017;

tables vaping* raceeth/ chisq;

run;

proc freq data=yrbs2017;

tables vaping* cigarette/ chisq;

run;

 

 

proc freq data=yrbs2017;

tables cigarette* vaping/ chisq;

run;

proc corr data = yrbs2017;

var age race sex grade cigarette vaping;

run;

 

unison
Lapis Lazuli | Level 10

dfamu,

Taking an excerpt from your code...

 

Change the resulting coding from character to numeric i.e. change "1", "2", "3" to 1, 2, 3

*...;
if raceeth = "Am Indian/ Alaska Native" and raceeth ="Asian" and raceeth
="Native Hawaiian/other Pl" and raceeth ="Multiple-Non-Hispanic"
and raceeth= " Multiple - Hispanic" then race = 1;
if Raceeth = "White" then race = 2;
if Raceeth= "Black" then race= 3;
*...;

-unison

-unison
mkeintz
PROC Star

It's a straightforward programming task to convert a character variable race to a numeric variable.  But it is not quite as simple an analysis task.  In your case, you have 3 levels, not 2, which will not provide the information you want to get in proc corr.  Should you convert white/black/multiple-Hispanic to 0/1/2 or to  1/2/0, or …… or to 2/1/0 (6 possible combinations)?  Each would give a different value in the correlation matrix.  You would get three different positive values and their 3 negatives. The problem is how to interpret a correlation coefficient intended for linear variables (of which binary is a subset here) to a 3-category variable.

 

I presume you could make two dummy variables  (white/black  and white/multiple,  or black/while and black/multiple …).  Then you would have two directly interpretable correlation coefficients.   However, I leave it to more authoritative respondents to better explain my observation.  

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
ballardw
Super User

@dfamu1989 wrote:

 

/* 1=female, 2=male*/

race=" ";

if raceeth = "Am Indian/ Alaska Native" and raceeth ="Asian" and raceeth

="Native Hawaiian/other Pl" and raceeth ="Multiple-Non-Hispanic"

and raceeth= " Multiple - Hispanic" then race = "1";

if Raceeth = "White" then race = "2";

if Raceeth= "Black" then race= "3";

 

 

First to have a variable to use in Proc Corr it must be numeric. The statement race=" "; means that you just created a CHARACTER variable. So get rid of:race=" ";

Second you explicitly assign character values "1" "2" and "3", which again are not what you want.

 

And then third the logic in

if raceeth = "Am Indian/ Alaska Native" and raceeth ="Asian" and raceeth
="Native Hawaiian/other Pl" and raceeth ="Multiple-Non-Hispanic"
and raceeth= " Multiple - Hispanic" then race = 1;

Is NEVER going to be true. One person from your data cannot have any multiple values of Raceth. So instead of AND you would want OR

if raceeth = "Am Indian/ Alaska Native" 
or raceeth ="Asian" 
or raceeth ="Native Hawaiian/other Pl" 
or raceeth ="Multiple-Non-Hispanic" 
or raceeth= " Multiple - Hispanic" then race = 1; 

SAS has a comparison operator called IN to compare a single variable to a list of values to use instead of a stack of OR statements:

if raceeth  in( "Am Indian/ Alaska Native" "Asian" "Native Hawaiian/other Pl" 
                "Multiple-Non-Hispanic" " Multiple - Hispanic" )then race = 1; 

I am not sure but I believe that you may also have a typo in "Native Hawaiian/other Pl" I suspect that instead of a lower case L that you should have an upper case I at the end:  "Native Hawaiian/other PI"

 

dfamu1989
Calcite | Level 5

IT WORKED!!!!! THANKS SO MUCHHHHH

ballardw
Super User

@dfamu1989 wrote:

IT WORKED!!!!! THANKS SO MUCHHHHH


Nice.

 

Now for some possibly less than good news: You may want to talk with someone about the structure of the YRBS data sets and weighting. The YRBS typically is a complex sample design and if you use Proc Corr with the weights you are not correctly applying the sample design information and can get misleading results from Proc Corr..

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 11 replies
  • 1821 views
  • 0 likes
  • 6 in conversation