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

Dear SAS Community.

 

I need your help with this. I have 2 Character Variables "Auftraggeber" and "Manufacturer" and want to create a new Variable "Sponsor" with the information from those variables. The information from the variable "Auftraggeber" is the information I need, but there are a lot of missings in this variable. So if there is a missing in the variable "Auftraggeber" , I want SAS to take the Information from the variable "Manufacturer" then. How can I do this?

Thank you for your help 🙂

 

I tried something like

data work.sponsors;
 set work.sponsors;
 sponsor = Auftraggeber;
 if Auftraggeber ne . then sponsor = Auftraggeber;
 if Auftraggeber = . then sponsor = Manufacturer;
 run;

1 ACCEPTED SOLUTION

Accepted Solutions
GinaRepole
SAS Employee

You've very nearly solved this one already! The main issue here is that you're comparing a character variable to the numeric missing value. What you really want is a comparison using " " as your missing value. Here's a small re-write you can use, and since you've already set sponsor to Auftraggeber upfront, the only time you need to worry about Manufacturer is if that value was missing.

 

data work.sponsors;
     set work.sponsors;
     sponsor = Auftraggeber;
     if Auftraggeber eq " " then sponsor = Manufacturer;
run;

 

View solution in original post

4 REPLIES 4
GinaRepole
SAS Employee

You've very nearly solved this one already! The main issue here is that you're comparing a character variable to the numeric missing value. What you really want is a comparison using " " as your missing value. Here's a small re-write you can use, and since you've already set sponsor to Auftraggeber upfront, the only time you need to worry about Manufacturer is if that value was missing.

 

data work.sponsors;
     set work.sponsors;
     sponsor = Auftraggeber;
     if Auftraggeber eq " " then sponsor = Manufacturer;
run;

 

andreas_lds
Jade | Level 19

Depending on the type of the variable you need to check . or " " (single, quoted blank). I recommend using the function missing(variable) to find missing values.

 

data work.sponsors;
   set work.sponsors;
   
   if missing(Auftraggeber) then do;
      sponsor = Auftraggeber;
   end;
   else do;
      sponsor = Manufacturer;
   end;
run;

You do have interesting variable names, if you don't want to translate var names, check out the regional groups.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1338 views
  • 1 like
  • 3 in conversation