BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dr2014
Quartz | Level 8

Hi all,

I imported a text tab delimited file into SAS 9.4 and the all the numeric fields are converted into an exponent of 10. So for  e.g how do I convert  5.8432957E13 into the actual number 58432957310473 in the sas file now? The value with the exponent E is a numeric field with a best12. format and informat.

 

Thanks in advance for your solutions.

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Run proc contents on your data. I suspect that what happened is that the default format of BEST12 was applied to a value that was longer than 12 digits. So SAS uses exponential notation to make it fit.

 

Then go back a verify that the value involved should actually be numeric. If the variable represents something like an account number or other ID then it should not be numeric at all. Especially if some original values may have exceeded 15 characters.

 

I would suggest that if you used Proc Import to read the data that you do so again but afterward

1) go to the log

2) copy the generated data step code to the editor

3) modify any informat/format statements to make sure that the variables are read as the correct type and with an appropriate length.

4) Save the code

 

Then when you need to read another similar file you just change the infile to point to the new source and change the output data set name. Then if you need to combine the two sets you will not have issues with variables of different types or lengths causing problems or errors.

View solution in original post

3 REPLIES 3
ballardw
Super User

Run proc contents on your data. I suspect that what happened is that the default format of BEST12 was applied to a value that was longer than 12 digits. So SAS uses exponential notation to make it fit.

 

Then go back a verify that the value involved should actually be numeric. If the variable represents something like an account number or other ID then it should not be numeric at all. Especially if some original values may have exceeded 15 characters.

 

I would suggest that if you used Proc Import to read the data that you do so again but afterward

1) go to the log

2) copy the generated data step code to the editor

3) modify any informat/format statements to make sure that the variables are read as the correct type and with an appropriate length.

4) Save the code

 

Then when you need to read another similar file you just change the infile to point to the new source and change the output data set name. Then if you need to combine the two sets you will not have issues with variables of different types or lengths causing problems or errors.

dr2014
Quartz | Level 8

Thanks for your reply @ballardw. I got the generated data step and will fix the length of the variables.

ballardw
Super User

If the value(s) are id or similar you likely want to change those to character. Simple with the data step replace the (likely ) infromat from BEST32. to $15. or similar to set a character length of 15 characters.

Typically I will set the length for ID variables to 1, 2 or 3 characters more than the longest I receive in the file. And things like names or other text add about 10 to 15% to allow for some slightly longer values in later 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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 3 replies
  • 4997 views
  • 0 likes
  • 2 in conversation