New Contributor
Posts: 2

# Creating variable with multiple values

Hey guys,

I need help creating a variable for sex. My data set currently has variables called "male" and "female, which have a numeric value for each observation. However, I am trying to create one variable for each observation called "sex", which should indicate the number of male and female participants in each observation. Is this possible?

Thanks,

Kelly867

Super User
Posts: 23,771

## Re: Creating variable with multiple values

Anythings possible with enough time, money and people.

For your problem you need to provide more details. A good way would be with sample data.

New Contributor
Posts: 2

## Re: Creating variable with multiple values

Okay...

Attached is a screenshot of the variables I have for my first 4 observations. I have 2 variables (numbermale and numberfemale) that I somehow want to combine into one variable.

The overall purpose of doing this is to create a variable that can be used for logistic regression. Sex is one of my predictor variables.

Am I approaching this wrong? Is there another option for running logistic regression with these variables?

- Kelly867

Super User
Posts: 23,771

## Re: Creating variable with multiple values

This isn't making sense to me. You typically do logistic regression with individual level data. If this isn't individual level data then I don't know how you'd combine this to make any sort of sense...in that case, leaving it as is seems to make the most amount of sense. You can't combine it to a single person and then use all three variables, you could combine it and use that vairable alone, and not use the gendered breakdown.

What are you expecting as output from combining these variables?

Note that we can't provide code based on images, and I'm not typing out your data for an example AND code that answers it. Please provide data samples as text.

Posts: 5,540

## Re: Creating variable with multiple values

Ths is how to do ths:

``````data want;
set have;
if numberFemale > 0 then do;
sex = "Female";
number = numberFemale;
output;
end;
if numberMale > 0 then do;
sex = "Male";
number = numberMale;
output;
end;
drop numbermale numberfemale;
run;``````
PG
Discussion stats
• 4 replies
• 372 views
• 1 like
• 3 in conversation