DATA Step, Macro, Functions and more

Truncated variables

Reply
Frequent Contributor
Posts: 121

Truncated variables

data hpi;
 infile "/file_location/InterestRates.txt";
 input var1-var1000;
run;

proc print data=hpi;
run;

I have the code posted in addition to the attached data. I am trying to import my data into SAS while avoiding the severe truncation that seems to be going on. Could someone please help?

 

Thank you. 

 

Trusted Advisor
Posts: 1,405

Re: Truncated variables

You have not defined any format to your variables.

The data is probably not truncated but in your report.

Add a format like:

data hpi;
 infile "/file_location/InterestRates.txt";
 input var1-var1000;
format var1-var1000 18.16 ;
run;

proc print data=hpi;
run;

You may need add the format statemnt, same or diffrent in the proc print.

Format 18.16 defines total display length is 18 caharacters with 16 decimal digits.

Super User
Super User
Posts: 6,502

Re: Truncated variables

[ Edited ]

You have two issues here. One you can fix and the other you cannot.

First the default format that is used to display numbers is BEST12., you can use other formats for displaying numbers.

Second SAS using 64 bit IEEE floating point format to store numbers. There is limit on the number of digits of precision that can be stored and many of the values in your text file exceed that limit.  But it most likley will not any real impact on using the data.

 

Here is example of one of the values in your text file that has too many digits to store precisely.

 

data test;
  input x 20.;
  put _infile_ / x / x 20.18 ;
cards;
0.021082546905855537
;
0.021082546905855537
0.0210825469
0.021082546905855500

 

Respected Advisor
Posts: 3,906

Re: Truncated variables

@maroulator

Looks like your source data doesn't have any end-of-line indicators but is a single stream of data. RECFM=N can deal with that.

As @Tom writes: SAS can only hold numerical values up to a length of 16 digits with full precision. If that's good enough then below should work; else read the digits into a character variable of sufficient length - but then you can't use it for calculations in a normal SAS data step.

data sample;
  infile "C:\temp\InterestRates.txt" dlm=' ' recfm=n;
/*  input c_var:$20. ;*/
  input n_var:best32.;
run;
Ask a Question
Discussion stats
  • 3 replies
  • 154 views
  • 1 like
  • 4 in conversation