Hi Community,
Well this my code
DATA ABC;
INFILE DATALINES MISSOVER DSD;
INPUT N1 N2 MS1$ MS2$;
DATALINES;
10,12,MS,
10,12,MS
10,12, ,MS
10,12,MS,
;
RUN;
PROC SQL;
CREATE TABLE WORK.BBC
SELECT N1,
N2,
ms1,
ms2,
(CASE WHEN(N1<N2)THEN MS1 OR MS2 END) AS FINAL_MS
FROM WORK.ABC;
QUIT;
IN BBC i want to create a new variable i.e. FINAL_MS in order to receive values from either ms1 or ms2 but it returning me logical value that is 1 as n1<n2. My need is it must receive either value from ms1 or ms2. How to do this ? thanks
PROC SQL;
CREATE TABLE CBC AS
SELECT N1,N2,MS1,MS2,CASE WHEN(N1<N2) THEN MS1 OR MS2 END AS FINAL_MS FROM ABC;
QUIT;
------------------------------------------------- following code worked well---------------------------------------
PROC SQL;
CREATE TABLE CBC AS
SELECT N1,N2,MS1,MS2,CASE WHEN(N1<N2) THEN COALESCE(MS1,MS2) END AS FINAL_MS FROM ABC;
QUIT;
thanks ballardw
Please provide details on which value, MS1 or MS2, should be returned. Your current code or description does not provide anything to tell use which of those values should be returned.
As i said i want to populate final_ms by getting values either MS1 variable or MS2 variable.
And values of MS1 & MS2 are already listed in datalines.
CASE WHEN N1 < N2 THEN MS1 ELSE MS2 END
PG i have other conditions too to write further, cant simply put ms2 in else.
simply all i want is final_ms should take value either from ms1 or ms2 whenever condition becomes true (n1<n2). thats it.
Lets try this again:
Your data currently shows that you may have missing for one of MS1 or MS2 variables. If that is always the case and you mean that you want the non-missing value as the result then perhaps you want
CASE WHEN(N1<N2)THEN coalescec(MS1,MS2) END
It really helps to show the exact desired result from your example data.
PROC SQL;
CREATE TABLE CBC AS
SELECT N1,N2,MS1,MS2,CASE WHEN(N1<N2) THEN MS1 OR MS2 END AS FINAL_MS FROM ABC;
QUIT;
------------------------------------------------- following code worked well---------------------------------------
PROC SQL;
CREATE TABLE CBC AS
SELECT N1,N2,MS1,MS2,CASE WHEN(N1<N2) THEN COALESCE(MS1,MS2) END AS FINAL_MS FROM ABC;
QUIT;
thanks ballardw
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 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: