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.2However, 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.2However, 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?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.