DATA Step, Macro, Functions and more

SAS override xls data type

Reply
Occasional Contributor
Posts: 5

SAS override xls data type

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
Super User
Posts: 7,854

Re: SAS override xls data type

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Super User
Posts: 3,260

Re: SAS override xls data type

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.

Super User
Super User
Posts: 7,987

Re: SAS override xls data type

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. 

Occasional Contributor
Posts: 5

Re: SAS override xls data type

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

Super User
Super User
Posts: 7,987

Re: SAS override xls data type

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.

Ask a Question
Discussion stats
  • 5 replies
  • 246 views
  • 1 like
  • 4 in conversation