Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Import excel in SAS

Posted on 2014-01-30
2
Medium Priority
?
960 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 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

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

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

Creating a Cordova application which allow user to save to/load from his Dropbox account the application database.
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
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…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

886 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