DATA Step, Macro, Functions and more

Truncated variables

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 122
Accepted Solution

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. 

 


Accepted Solutions
Solution
‎09-18-2017 05:08 PM
Trusted Advisor
Posts: 1,569

Re: Truncated variables

Posted in reply to maroulator

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.

View solution in original post


All Replies
Solution
‎09-18-2017 05:08 PM
Trusted Advisor
Posts: 1,569

Re: Truncated variables

Posted in reply to maroulator

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: 7,050

Re: Truncated variables

[ Edited ]
Posted in reply to maroulator

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: 4,173

Re: Truncated variables

Posted in reply to maroulator

@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;
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 197 views
  • 1 like
  • 4 in conversation