04-15-2015 01:11 AM
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.
04-15-2015 01:42 AM
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.
04-15-2015 03:26 AM
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.
04-15-2015 04:26 AM
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.