?
Solved

Import excel in SAS

Posted on 2014-01-30
2
Medium Priority
?
899 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

800 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