There are tables for different dates where the column name changed for some reason. I'm trying to: 1). detect if the column of a specific name exists in the table. 2). If it exists in the table, then in PROC SQL SELECT it will use that column name. If the specified column name does not exist in the table (i.e., it has a slightly different naming convention), then I want PROC SQL SELECT to use an alternative column name that I specify in advance (it appears that only two different naming conventions were used for the subject column). The code I am testing to identify a specified missing column (item #1) was taken from a different SAS Community topic, but it doesn't appear to work properly: data tbl1;
input ID x1,x2 ;
cards;
1 10 15
2 20 25
3 30 35
4 40 45
5 50 55
;
run;
proc sql noprint;
select count(*) into :varexist
from dictionary.columns
where libname="WORK" and memname="TBL1" and upcase(name)="X3";
quit;
data tbl2;
set tbl1;
if not &varexist then x3=.;
run;
If I use upcase(name)="X3" or upcase(name)="X2", a column X3 is created with "." values. Thoughts on how item #1 and #2 can be accomplished?
... View more