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-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 729 views
  • 1 like
  • 3 in conversation