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