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.
V1 | V101 | V115 | V116 | V117 |
763 | United Kingdom | |||
764 | Switzerland | |||
4911 | United Kingdom | 34850 | 34880 | 0 |
4914 | United States | |||
64138 | United States | |||
4915 | United States |
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.
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.
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.
After transforming xls to xlsx, the problem is actually solved. Thanks, everybody.:smileylaugh:
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.
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.
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.