How to do -- Case when then select ( column A from table A) else select column b from table b.
Thanks
When WHAT? How are you joining table A and table B so that both available to reference the CASE?
select
case when ( ????) then A.A else B.B end as A_or_B
from A , B
;
Or are you taling about generating code based on some external condition. So perhaps the value of some macro variable? If so then use macro logic to conditionally generate the statement you want to create.
%if &XX= OPTION1 %then %do;
select A from A;
%end;
%else %do;
select B from B;
%end;
Is this what you are trying to do?
proc sql;
select case when <put logic here> then a.column_A else b.column_B end as new_column
from table_A as a
join table_B as b on <put join here>;
quit;
SELECT CASE WHEN A.ID = X THEN A.COLUMN
ELSE B.COLUMN
END AS NAME
FROM TableA A
JOIN TableB B on A.ID = B.ID
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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: