Solved

Import excel in SAS

Posted on 2014-01-30
2
829 Views
Last Modified: 2016-02-10
Hi,

I have a SAS dataset with 73 fields.
I import with the following code an xlsx file with the same fieldnames as the SAS dataset:
options mprint symbolgen mlogic ;
libname xls pcfiles path='c:\data\cyfcorr.xlsx';
libname xxx 'c:\data\';
data cyf_tb;
    set xxx.cyf;
run;
data cyf_corr;
    set xls.'Sheet1$'n;
run;
libname xls clear;

data test;
   update bcact start decri etc....;
   by key;
run;
I get the following errors, 72 times.
ERROR: Variable bcact has been defined as both character and numeric.
ERROR: Variable start has been defined as both character and numeric.
ERROR: Variable decri has been defined as both character and numeric.
etc......

How can i solve this!

Tx
0
Comment
Question by:sonmic
  • 2
2 Comments
 
LVL 8

Expert Comment

by:ShannonEE
ID: 39822626
Hi there sonmic,

If you want to go the way you have set out above then

change

libname xls pcfiles path='c:\data\cyfcorr.xlsx';

Open in new window

to
libname xls pcfiles path='c:\data\cyfcorr.xlsx'
                     DBSASTYPE=(bcact = NUMERIC  start=NUMERIC
                     decri=NUMERIC);

Open in new window


That is assuming that your current SAS dataset    xxx.cyf   has numeric data  in these 3 columns.  The DBSASTYPE tells sas when importingb the data to use the type specified instead of trying to guess the type.

However it is possible (because of the contents of the spreadsheet) that the data wont convert very well.  You will also need to review the spreadsheet in excel and check if the column is truly numeric all the way down.

-----

My guess is that you need the columns to be numeric.  It might be that the sas dataset    xxx.cyf    has these columns as character.  In that case the libname statement should have the DBSASTYPE set to CHAR.

Read all about it in

http://support.sas.com/documentation/cdl/en/acpcref/63181/HTML/default/viewer.htm#p0w9ox0g4b3yphn1deuim9yvu092a.htm


 Ian
0
 
LVL 8

Accepted Solution

by:
ShannonEE earned 500 total points
ID: 39822648
Hi there sonmic,  (again)

There are many other ways of importing spreadsheet data into SAS.

If you have enterprise guide then you will have better control in the importing if you add the excel spreadsheet to your current project.

Another way -  you can go into excel and export the data as either tab or comma separated text files.  Then importing into SAS is easy and you have the benefit of being able to use an editor to check the data before importing.

Ian
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Many companies are looking to get out of the datacenter business and to services like Microsoft Azure to provide Infrastructure as a Service (IaaS) solutions for legacy client server workloads, rather than continuing to make capital investments in h…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question