BookmarkSubscribeRSS Feed
JohnChen_TW
Quartz | Level 8

Hi everyone,

I'm using SAS 9.3. I met a problem while importing excel sheet included a number of 0.0655548562875890.

How should I do to import the entire number into SAS?

If I use BEST32., this number would be read as 0.06555485628758...

It the limit length of decimal place of imported number is 14? If so, how to make it round off to 0.06555485628759?

 

Here is my code

libname xl excel "xxxxxxx.xls" access=readonly header=yes;

proc sql;
create table outfile1 as
select SUBJID, SEX, RACE, AREA
    A1 format=30.20,
from xl.'Sheet1$'n;
select * from outfile1;
quit;

libname xl clear;

data want; set outfile1; format A1 BEST32.; run;

 

2 REPLIES 2
RW9
Diamond | Level 26 RW9
Diamond | Level 26

There is a limit to the number of decimal places in SAS.  If your number is bigger than that then you can either read that in as a text string, process it that way, round it in Excel, or use a third party library like python to process it.

Try the advice in this thread:

https://communities.sas.com/t5/SAS-Enterprise-Guide/Reading-Excel-file-with-large-decimal-Places/m-p...

AhmedAl_Attar
Rhodochrosite | Level 12

Hi,

 

Check out page 10 of the following paper So, Your Data are in Excel!

To explicitly change the type of the imported column(s), you use the dbsastype=() data set option for your Excel source sheet.

 

Here is another paper worth look at  The Little Engine That Could: Using LIBNAME Engine Options to Enhance Data Transfers Between SAS and...

 

This way you can preserve the accuracy of your incoming numbers as characters, and perform required manipulations.

SAS Online Documentation - DBSASTYPE= Data Set Option

 

 

Hope this helps,

Ahmed

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 2192 views
  • 0 likes
  • 3 in conversation