I have this dataset
and I want to create a new variable based on C3 and C3_F.
When C3 has a value I want this value. When not, like the green example shown, I want the C3_F value.
Can you help me please?
The link works for me.
Here how this could look like in a data step. Make sure to define the length of new_var long enough to hold the string (=the greater length of your two source variables)
length new_var $20; new_var=coalescec(cae3,cae3_fue);
You could use the coalescec() function documented here.
The link works for me.
Here how this could look like in a data step. Make sure to define the length of new_var long enough to hold the string (=the greater length of your two source variables)
length new_var $20; new_var=coalescec(cae3,cae3_fue);
@Patrick the link does not work:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Thank you very much @Patrick !
It worked!
I used this code:
DATA D;
set D;
length C3_E $20.;
C3_E=coalescec(c3,c3_f);
run;
Don't just use the length of $20 from my sample but chose a length which matches your source variables. If the length is too short then you will truncate the string, if it's too long then you're wasting space.
You can run below script. Then look-up in the report what lengths your two source variables have and use the bigger of the two values in the length statement for your new variable.
proc contents data=DEM_MES.MERGEEFATURADMRSS202001;
run;quit;
I took the liberty to update the link, it should work now everywhere.
(I just copy/pasted the link that I get from the documentation website, I have no clue what was wrong)
Thank you.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.