I imported a CSV file into SAS using the infile command. There was no error reported. Today I found an error in the imported dataset. In the CSV file, there is a numeric variable whose values are floating numbers (e.g., 3828443.49) in some rows and intergers (e.g., 3500000) in other rows. In the import code, I specified
informat my_var 12.2
However, this introduced errors. While the floating numbers are correctly imported, those intergers ending with multiple zeros got truncated. It seems that many of them lost the last 2 zeros. So my question is, what is a good practice for avoiding this numeric issue when importing CSV files?
Specifying an informat of 12.2 means you expect the data to always have 2 decimal spaces when being read.
So 35000 read with 12.2 would return 350.00 which is why you're losing your last two values.
You should likely read it as 8. and then format it as 8.2?
@xyxu wrote:
I imported a CSV file into SAS using the infile command. There was no error reported. Today I found an error in the imported dataset. In the CSV file, there is a numeric variable whose values are floating numbers (e.g., 3828443.49) in some rows and intergers (e.g., 3500000) in other rows. In the import code, I specified
informat my_var 12.2
However, this introduced errors. While the floating numbers are correctly imported, those intergers ending with multiple zeros got truncated. It seems that many of them lost the last 2 zeros. So my question is, what is a good practice for avoiding this numeric issue when importing CSV files?
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.