BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
maroulator
Obsidian | Level 7
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. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

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

3 REPLIES 3
Shmuel
Garnet | Level 18

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.

Tom
Super User Tom
Super User

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

 

Patrick
Opal | Level 21

@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;

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!

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
  • 3 replies
  • 4385 views
  • 1 like
  • 4 in conversation