Hi everyone, my dataset in excel has multiple columns for race. Each column has a 1 if someone chose that race and a blank they did not (they would have a 1 in another column). I am trying to combine these all into one race variable for a logistic regression. Attached is a picture of how the raw data looks:
@Sbon08 wrote:
Hi everyone, my dataset in excel has multiple columns for race. Each column has a 1 if someone chose that race and a blank they did not (they would have a 1 in another column). I am trying to combine these all into one race variable for a logistic regression. Attached is a picture of how the raw data looks:
Is this going to be a dependent variable or independent in the model?
What would the values of your one value look like? Are all of the Q2_1 through Q2_9 to be combined or does one of those mean something such that it should not be combined such as a "refused to answer" code that really should not occur with other values?
And are the variables numeric or character?
By any chance did a previous step replace zero (0) values with missing? If so remove that step and something like this would work:
data example; input Q2_1 - Q2_4; length r $ 4; r = cats(of Q2_:); datalines; 1 0 0 0 1 0 1 0 0 0 0 1 ; run;
Using only 4 variables as I'm too lazy to make 10 when 4 demonstrates what goes on.
You would need a place holder in any case.
The following code shows one way to replace 0 for missing values.
data example;
informat Q2_1 - Q2_4 $1.;
input Q2_1 - Q2_4 ;
array q Q2_1 - Q2_4;
do i= 1 to dim(q);
if missing(q[i]) then q[i]='0';
end;
length r $ 4;
r = cats(of Q2_:);
drop;
datalines;
1 . . .
1 . 1 .
. . . 1
;
run;
If you variables are numeric the only real change to the code (other than not reading data) is to use =0; instead of ='0';
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.