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? 


 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

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
  • 1 reply
  • 534 views
  • 0 likes
  • 2 in conversation