I have multiple excel files where the variable length is different. Once in SAS I need to combine these files so I need to use libname excel code and read in the variable names using DBSASTYPE. Two of my variable names in excel contain symbols (+ and .) Without going into each excel file and changing the column name to exclude the symbol, is there code that will ignore those symbols?
The column in excel is ADD+, how do I code that in the DBSASTYPE lines???
LIBNAME WrkBk EXCEL "filepath/file" MIXED=YES;
DATA test1;
SET WrkBk."Subject$"n
(DBSASTYPE=(
"PACKAGE NO"='char(8)'
"SEQ"='char(8)'
"ID"='char(13)'
"NAME"='char(27)'
"ADD+"='char(27)'
));
RUN;
LIBNAME WrkBk CLEAR;
LIBNAME WrkBk EXCEL "filepath/file" MIXED=YES;
DATA test1;
SET WrkBk."Subject$"n
(DBSASTYPE=(
"PACKAGE NO"n='char(8)'
SEQ='char(8)'
ID='char(13)'
NAME='char(27)'
"ADD+"n='char(27)'
));
RUN;
LIBNAME WrkBk CLEAR;
This is how you reference non-SAS compatible column names. The rest of the code is untested.
LIBNAME WrkBk EXCEL "filepath/file" MIXED=YES;
DATA test1;
SET WrkBk."Subject$"n
(DBSASTYPE=(
"PACKAGE NO"n='char(8)'
SEQ='char(8)'
ID='char(13)'
NAME='char(27)'
"ADD+"n='char(27)'
));
RUN;
LIBNAME WrkBk CLEAR;
This is how you reference non-SAS compatible column names. The rest of the code is untested.
Thanks SASKiwi. Adding the n seems to get me past the ADD+ but I forgot to include in my orig post the var name that has the .
Adding n to this variable still produces an error saying invalid column name. Any ideas on how to resolve this?
I currently have
"AB. ADD"n='char(13)'
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 25. 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.