BookmarkSubscribeRSS Feed
Jarvin99
Obsidian | Level 7

Hi all,

How to import csv with variables of infinite decimals? Attached is my sample csv file.

Also, anyone knows how to import a number with more than 8 length, such as 123456789, 897654391?

 

Thank you so much.

4 REPLIES 4
Kurt_Bremser
Super User

The length of a numeric variable is the number of bytes used to store the binary number (same as in Excel). It is not the maximum number of decimal digits. What is limited is the precision (up to 15 decimal digits).

You did not attach a csv file, but an Excel workbook. You need PROC IMPORT or LIBNAME XLSX for this.

Jarvin99
Obsidian | Level 7

Thank you for your reply.

So you mean even if I choose length 8 for my variables xi_real and xi_nominal, the number of decimal digits will still be up to 15?

 

So sorry for wrong type of the file. Here you go.

Tom
Super User Tom
Super User

No need to attach a file to show a few lines of text.

id_num,xi_real,xi_nominal,transfer,id,issue_date,filing_date
1568057,1.7043058,0.30166212,10,14082,1/5/1926,6/23/1920
1568124,0.87447679,0.1547824,210,12503,1/5/1926,6/12/1920
1568134,0.87447679,0.1547824,0,12503,1/5/1926,9/9/1922
1568141,1.9720176,0.34904712,2,10401,1/5/1926,8/13/1920
1568142,1.9720176,0.34904712,1,10401,1/5/1926,8/13/1920
1568143,1.9720176,0.34904712,3,10401,1/5/1926,8/13/1920
1568144,1.9720176,0.34904712,2,10401,1/5/1926,8/13/1920
1568145,1.9720176,0.34904712,0,10401,1/5/1926,2/26/1921
1568163,0.87447679,0.1547824,1,12503,1/5/1926,5/3/1920

That file is trivial to read.

data want;
  infile 'Book1.csv' dsd firstobs=2 truncover;
  input id_num xi_real xi_nominal transfer id issue_date :mmddyy. filing_date :mmddyy.;
  format issue_date filing_date yymmdd10.;
run;

Tom_0-1656162964308.png

 

Unfortunately it looks like you generated it with CR as the end of line character instead of something normal like LF (unix) or CRLF (windows).   Are you running Excel on a Mac?  Excel on the mac seems to have never learned that MacOS is now Unix based.

;
1741    infile 'c:\downloads\Book1.csv' recfm=f lrecl=100;
1742    input;
1743    list;
1744  run;

NOTE: The infile 'c:\downloads\Book1.csv' is:
      Filename=c:\downloads\Book1.csv,
      RECFM=F,LRECL=100,File Size (bytes)=567,
      Last Modified=25Jun2022:08:41:34,
      Create Time=25Jun2022:08:41:34

RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

1   CHAR  id_num,xi_real,xi_nominal,transfer,id,issue_date,filing_date.1568057,1.7043058,0.30166212,10,14082,1
    ZONE  6656762765766627656666666277667667266267776566762666666566760333333323233333332323333333323323333323
    NUMR  94FE5DC89F251CC89FEFD9E1CC421E3652C94C93355F4145C69C9E7F4145D1568057C1E7043058C0E30166212C10C14082C1

2   CHAR  /5/1926,6/23/1920.1568124,0.87447679,0.1547824,210,12503,1/5/1926,6/12/1920.1568134,0.87447679,0.154
    ZONE  2323333232332333303333333232333333332323333333233323333323232333323233233330333333323233333333232333
    NUMR  F5F1926C6F23F1920D1568124C0E87447679C0E1547824C210C12503C1F5F1926C6F12F1920D1568134C0E87447679C0E154

3   CHAR  7824,0,12503,1/5/1926,9/9/1922.1568141,1.9720176,0.34904712,2,10401,1/5/1926,8/13/1920.1568142,1.972
    ZONE  3333232333332323233332323233330333333323233333332323333333323233333232323333232332333303333333232333
    NUMR  7824C0C12503C1F5F1926C9F9F1922D1568141C1E9720176C0E34904712C2C10401C1F5F1926C8F13F1920D1568142C1E972

Are you sure you posted an example of some lines from the original file and not the output from a version of the file created by Excel?  Note that EXCEL will make other changes to the format of the file, including changing the way the dates appear.  If the original file is using CR as end of line character then add TERMSTR=CR option to the INFILE statement.

 

 

Kurt_Bremser
Super User

The number of digits which can be precisely stored does not limit the number of digits to the left of the decimal point, these are only limited by the maximum exponent of the 8-byte real storage. So you can easily store numbers used by astrophysicists, just with precision guaranteed only for the 15 most signiificant digits.

The maximum readable field width for numeric informats is 32.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 4 replies
  • 599 views
  • 0 likes
  • 3 in conversation