BookmarkSubscribeRSS Feed
J_J_J
Obsidian | Level 7

I'm trying to import excel file in .xls format to SAS using code:

 

PROC IMPORT out=WORK.test 

DATAFILE='/place/where/file.xls'
DBMS=xls REPLACE;
sheet='name';
getnames=YES;
mixed=no;
RUN;

 

I need to use encoding='UTF-8' to replace some symbols in different columns.

How should I write this code to get right result?

7 REPLIES 7
Ksharp
Super User
filename x '/place/where/file.xls' encoding='utf-8';


PROC IMPORT out=WORK.test 

DATAFILE=x

DBMS=xls REPLACE;
sheet='name';
getnames=YES;
mixed=no;
RUN;
J_J_J
Obsidian | Level 7

Thanks, but it doesn't work. Symbols like � stay.

Ksharp
Super User

Then Save this xls file into CSV file . and try import again .

andreas_lds
Jade | Level 19

@J_J_J wrote:

Thanks, but it doesn't work. Symbols like � stay.


Interesting. When importing text-files that contain unicode-chars which aren't in the active session encoding (Latin1 on our server), sas writes an error/warning to the log and removes the char from the string. I am wondering why sas inserts fancy chars when reading an excel file containing unicode chars.

Ksharp
Super User

Oh. I just be ware of that you need change your sas session into UTF-8 encoding as well to make � appeared.

Shmuel
Garnet | Level 18

I had similar issues when retrieving data from external origin into SAS_UE, though it is predefined with encoding='utf-8' .

I found that enlarging LENGTH of specific variables was the solution.

J_J_J
Obsidian | Level 7

Thanks to everybody. None of the proposed options unfortunately helped. The problem was solved only by changing the format of the file from .xls to .xlsx, fortunately it was possible.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 10640 views
  • 1 like
  • 4 in conversation