I have two columns which I want to combine into one.
It looks like this:
A B
0.12 .
0.02 0.02
0.20 0.28
. .
. 0.12
0.13 0.15
For the new column:
In principle I want the value from the column A.
If that value is missing, I want the value from column B.
If both are missing I want ‘no sample’.
Can anyone help me with creating this new column with these values? Thank you!
Should your new variable be character or numeric? A numeric variable can't take on the value "no sample". But it can take on a special missing value (such as .N) that would differentiate it from other values. You could use:
newvar = coalesce(a, b);
if newvar=. then newvar=.N;
Should your new variable be character or numeric? A numeric variable can't take on the value "no sample". But it can take on a special missing value (such as .N) that would differentiate it from other values. You could use:
newvar = coalesce(a, b);
if newvar=. then newvar=.N;
I agree with @Astounding that coalsece is a good idea. I would check the logic when you have both values however, are you sure you want the first and not the min or max? Don't know what your data is also, but in Pharma data where we follow CDISC structures, you should have a numeric and character version of these types of variables, the reason being that you can then capture all numbers in a numerical variable for processing - makes using numbers easy, and also a character representation for reporting which can contain futher information that cannot be captured in a numeric, e.g:
RESULT RESULT_C
0.12 0.12
. No sample
...
E.g:
data want; set have; result=coalesce(a,b); /* Or: result=min(a,b); */ result_c=ifc(a=. and b=.,"No sample",strip(put(min(a,b),best.))); run;
If your using anything other than SAS, I would avoid formats as these are SAS specific and proprietary to the software, the above two columns however are accessible to any other software.
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!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.