BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Hedegaard
Calcite | Level 5

Hello,

I have a .txt-file (called number.txt) containing only 2 rows, where the first row is the headline "Number", and where the second row is a number of 1000 digits. I try to import this number by using the following proc import step:

proc import datafile="C:\Documents and Settings\Desktop\Euler\number.txt"

                            out = number

                            replace;

run;

This gives me the following log error:

2611  proc import datafile="C:\Documents and Settings\Desktop\number\number.txt";
ERROR: Output SAS data set must be provided.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds

2612              out = number
2613              replace;
2614  run;


2615  proc import datafile="C:\Documents and Settings\Desktop\number\number.txt"
2616              out = number
2617              replace;
2618  run;

2619   /**********************************************************************
2620   *   PRODUCT:   SAS
2621   *   VERSION:   9.1
2622   *   CREATOR:   External File Interface
2623   *   DATE:      02APR12
2624   *   DESC:      Generated SAS Datastep Code
2625   *   TEMPLATE SOURCE:  (None Specified.)
2626   ***********************************************************************/
2627      data NUMBER                                      ;
2628      %let _EFIERR_ = 0; /* set the ERROR detection macro variable */
2629      infile 'C:\Documents and Settings\Desktop\number\number.txt' delimiter='09'x MISSOVER DSD lrecl=32767 firstobs=2 ;
2630         informat Number best32. ;
2631         format Number best12. ;
2632      input
2633                  Number
2634      ;
2635      if _ERROR_ then call symputx('_EFIERR_',1);  /* set ERROR detection macro variable */
2636      run;

NOTE: The infile 'C:\Documents and Settings\Desktop\number\number.txt' is:
      File Name=C:\Documents and Settings\Desktop\number\number.txt,
      RECFM=V,LRECL=32767

NOTE: Invalid data for Number in line 2 1-1000.
RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0
2         7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843
     101  8586156078911294949545950173795833195285320880551112540698747158523863050715693290963295227443043557
     201  6689664895044524452316173185640309871112172238311362229893423380308135336276614282806444486645238749
     301  3035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776
     401  6572733300105336788122023542180975125454059475224352584907711670556013604839586446706324415722155397
     501  5369781797784617406495514929086256932197846862248283972241375657056057490261407972968652414535100474
     601  8216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586
     701  1786645835912456652947654568284891288314260769004224219022671055626321111109370544217506941658960408
     801  0719840385096245544436298123098787992724428490918884580156166097919133875499200524063689912560717606
     901  0588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450 1000
Number=. _ERROR_=1 _N_=1
NOTE: 1 record was read from the infile 'C:\Documents and Settings\Desktop\number\number.txt'.
      The minimum record length was 1000.
      The maximum record length was 1000.
NOTE: The data set WORK.NUMBER has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds


Errors detected in submitted DATA step. Examine log.
1 rows created in NUMBER                                    from C:\Documents and Settings\Desktop\number\number.txt.

ERROR: Import unsuccessful.  See SAS Log for details.
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE IMPORT used (Total process time):
      real time           0.17 seconds
      cpu time            0.06 seconds

If I reduce the number in the text file, I tried 20 digits or so, it does work fine.

What I really want to do is to create an array of length 1000, where each digit of the number occupies an entry of the array. If I restrict the number in the .txt-file to have only 26 digits (for instance), then I use the following code:

data bla;

     set number;

     array digit(1:26) digit1 - digit26;

     do i = 1 to 26;

          digit = substr(number,i,1);

     end;

run;

The only problem is that the number in the number dataset is written as "7.3167177E25", so the array elements will end up being "7", ".", "3", "1", ..., "1", "7", "7", ".", "2", "5", ".", ".", ".", ..., which is not what I was hoping for.

So my question is two-fold.

1) How do I get proc import to read in the number from the data set even though it has 1000 digits?

2) How do I avoid that this number is saved in scientific notation, but rather than all digits are maintained?

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Do not type the numbers into a program. Read them from a file.

data want ;

  infile "C:\Documents and Settings\Desktop\number\number.txt" lrecl=1000;

  input digits $1000.;

run;

View solution in original post

7 REPLIES 7
Hima
Obsidian | Level 7

Can you try the below code and let me know how it works?

PROC IMPORT OUT= NUMBER

            DATAFILE= "C:\Documents and Settings\Desktop\Euler\number.txt"

            DBMS=TAB REPLACE;

     GETNAMES=YES;

     DATAROW=2;

RUN;

Hedegaard
Calcite | Level 5

Hello, When I submit your code, I still get the same error message (I changed the library from "Euler" to "number" at some point). Ungh, for some reason the log message appeared all jumbled when I posted it here. I've attached it instead.

Tom
Super User Tom
Super User

It doesn't look like you are trying to read in an actual number. Instead your file just looks like a stream of digits.

Skip the IMPORT and just write the data step yourself.

You cannot store more than about 15 digits of precision in an 8 bytes floating point number.

So if you want streams of digits longer than that you will need to treat them as character strings instead.

Hima
Obsidian | Level 7

I agree what Tom says. That might be a better approach.

Hedegaard
Calcite | Level 5

Thanks.

If I write in the number directly in my data step, SAS pops up with this error message:

"Submitted code contains lines longer that 960 characters. SAS is unable to process lines longer than 960 characters. Your submission has been aborted."

I can split the number in half, though, and save it in two different variables and then concatenate them. However, I'm not much for these ad hoc solutions, is there an option where you can increase the length of lines that SAS can process?

For completeness, could I possibly get the proc import solution to work? I mean, is there a way to specify that I want the 1000 digits in the text file to be read in as a character string?

Tom
Super User Tom
Super User

Do not type the numbers into a program. Read them from a file.

data want ;

  infile "C:\Documents and Settings\Desktop\number\number.txt" lrecl=1000;

  input digits $1000.;

run;

Tom
Super User Tom
Super User

If you want to type long strings into a program then just break them into pieces.

digits='1234567890123456789012345678901234567890123456789012345678901234567890'
     ||'1234567890123456789012345678901234567890123456789012345678901234567890'
     ||'1234567890123456789012345678901234567890123456789012345678901234567890'
;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 7 replies
  • 3512 views
  • 6 likes
  • 3 in conversation