BookmarkSubscribeRSS Feed
dxhuan
Calcite | Level 5

Hi SAS Users,

I'd like to import some xls data into SAS. First of all, I use VBA to specify all the xls columns as text. Then I use PROC IMPORT to read the data into SAS. But SAS seems to be mistakenly reading some columns as numeric. My SAS version is 9.4.


My data look like the following. All columns are text in xls. SAS reads V1 and V101 as character variable, but read V115-V117 as numeric variables.

I thought PROC IMPORT just takes whatever is given in the raw data. Why is it overriding? I carried out the same exercise in Stata. Any idea will be appreciated. Thanks.

V1V101V115V116V117
763  United Kingdom                                                                                                                                                    
764Switzerland
4911United Kingdom34850348800
4914United States
64138United States
4915United States
5 REPLIES 5
Kurt_Bremser
Super User

PROC IMPORT makes its own guess about the data types, which is its strength and also its weakness.

If you need to force data types and formats, write the data step manually (PROC IMPORT inspects the data and creates a data step on its own, you can find that data step in the log).

Keep in mind that PROC IMPORT is good for a "quick shot", but not for stable, repeatable results; it's much too flexible. Just some unexpected entries in the file can make it switch to another data type and cause havoc in further processing.

SASKiwi
PROC Star

One quick and dirty solution is to put a dummy row of data as the first data row and populate all columns to be read with characters like XXXX. Not something to repeat a lot but OK for a one-off.

RW9
Diamond | Level 26 RW9
Diamond | Level 26

If your familiar with Excel, then export the data as CSV, i.e. text based, delimited.  Then you can write your own datastep to read in the text file in exactly the formats you want.  Proc import is just a best guess scenario and doesn't know your data. 

dxhuan
Calcite | Level 5

After transforming xls to xlsx, the problem is actually solved. Thanks, everybody.:smileylaugh:

RW9
Diamond | Level 26 RW9
Diamond | Level 26

Just goes to show that proc import isn't the best option for importing data, and Excel is very far from the best option for transfer of data.

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