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;
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;
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;
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.
Thank you!!!!!!
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.
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.