BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
klj81
Fluorite | Level 6

Hello!

I am completing an assignment where I have to use the set statement to combine three different data sets. One set is assigned with 0 for males, the second set assigns 1 for females, and the third is left blank for unknown gender. These were .sas files that I uploaded into SAS university edition. When I tried to use a set statement to combine them I get the error "ERROR: Variable Gender has been defined as both character and numeric."

i believe it is because the unknown data set for Gender has the variable as a character (see screenshot).

Is there any way of fixing this or changing this in sas so that it is numeric?

 

Screen Shot 2019-02-14 at 9.05.00 PM.png

 

I also attached the unknown file below.

I apologize for the question, I am very new to SAS and trying but it has been a struggle.

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star
If you know that GENDER values are always blank in the third data set, just get rid of it when combining the data sets:

set first second third (drop=gender);

View solution in original post

5 REPLIES 5
Astounding
PROC Star
If you know that GENDER values are always blank in the third data set, just get rid of it when combining the data sets:

set first second third (drop=gender);
klj81
Fluorite | Level 6

Thanks so much for the help. This worked perfectly!

klj81
Fluorite | Level 6
Unfortunately I can’t drop it from the final table because that is part of the assignment to sort by gender and print the results. The problem is with the numerical value from two sets and the character value from one I can’t figure out how to get them to combine...
andreas_lds
Jade | Level 19

Please post more information about the datasets you are using. Posting data as data-step using datalines will help use to help you. Additionally explain what you want as result, which values are expected?

 

You could rename the numeric Gender variable:

  set first second third (rename=(Gender=GenderNum));
Astounding
PROC Star
My suggestion doesn't drop gender from the final table. It keeps the values found in the first 2 tables but omits values found in the third table. That's the reason the program needs gender to be blank in the third table. If it's not blank all the time, we need to know more about what's in it.

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
  • 5 replies
  • 1605 views
  • 0 likes
  • 3 in conversation