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.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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