how to write DBSASTYPE code for excel column names with symbols

Reply
New Contributor
Posts: 2

how to write DBSASTYPE code for excel column names with symbols

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;

Super User
Posts: 3,475

Re: how to write DBSASTYPE code for excel column names with symbols

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.

New Contributor
Posts: 2

Re: how to write DBSASTYPE code for excel column names with symbols

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)'

Super User
Posts: 5,615

Re: how to write DBSASTYPE code for excel column names with symbols

At this point it seem easier to rename the columns in Excel instead.
That said, check that you have
OPTIONS VALIDVARNAME=ANY;
Data never sleeps
Ask a Question
Discussion stats
  • 3 replies
  • 78 views
  • 0 likes
  • 3 in conversation