BookmarkSubscribeRSS Feed
xyxu
Quartz | Level 8

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? 

1 REPLY 1
Reeza
Super User

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? 


 

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 912 views
  • 0 likes
  • 2 in conversation