## PROC IMPORT truncating numbers

Solved
Occasional Contributor
Posts: 19

# PROC IMPORT truncating numbers

Hi all,

Is there a way to keep my PROC IMPORT procedure from truncating my unique identifier?  It is about 20 numbers long and is converted to scientific notation using my procedure.  It uses the best12 format and I'm importing from a txt delimited file with vertical bars as the delimeter.  The last two digits are what make these identifiers unique and I need them, not the scientific notation.

Thanks for any help!

Accepted Solutions
Solution
‎01-23-2015 06:03 PM
Super User
Posts: 8,093

## Re: PROC IMPORT truncating numbers

20 digits are too many for a number.  SAS stores numbers as 8 bytes floating point and so only has 17 digits of precision.

It is probably better to read the file using a data step instead of using PROC IMPORT.  PROC IMPORT will have to guess as to the data types for your variables.

data mydata ;

infile 'mydata.txt' dsd dlm='|' lrecl=32000 truncover firstobs=2;

length ID \$20 ..... ;

input ID .... ;

run;

Fill in the names for the rest of your variables.  For date and time variables add INFORMAT and FORMAT statements.

All Replies
Solution
‎01-23-2015 06:03 PM
Super User
Posts: 8,093

## Re: PROC IMPORT truncating numbers

20 digits are too many for a number.  SAS stores numbers as 8 bytes floating point and so only has 17 digits of precision.

It is probably better to read the file using a data step instead of using PROC IMPORT.  PROC IMPORT will have to guess as to the data types for your variables.

data mydata ;

infile 'mydata.txt' dsd dlm='|' lrecl=32000 truncover firstobs=2;

length ID \$20 ..... ;

input ID .... ;

run;

Fill in the names for the rest of your variables.  For date and time variables add INFORMAT and FORMAT statements.

Super User
Posts: 13,532

## Re: PROC IMPORT truncating numbers

Proc import generated a SAS datastep program similar to Tom's stub. It would be in the log. You can either copy the text from the log or use F4 key to Recall the program text into the editor.

Modify the code as Tom suggested, looking at other variables as well. If this going to me done more than once take a good look at any variables, especially character to consider making them longer as the next iteration of the data may be longer.

Consider specifying better variable names, especially if you get varxx type name, and adding meaningful labels for the variables.

Save the code and you'll be ready to go next by changing the infile information and possibly the output data set name.

🔒 This topic is solved and locked.