BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HN2001
Obsidian | Level 7

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;

1 ACCEPTED SOLUTION

Accepted Solutions
SASKiwi
PROC Star
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.

View solution in original post

4 REPLIES 4
SASKiwi
PROC Star
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.

HN2001
Obsidian | Level 7

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

HN2001
Obsidian | Level 7
Using a # helped with the . in the name
"AB# ADD"n='char(13)'
LinusH
Tourmaline | Level 20
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 1119 views
  • 0 likes
  • 3 in conversation