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
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.