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

I came across a SAS variable the other day that had both format and informat assigned to it. (I forgot to take a screenshot)

 

I am just curious that what happens if the format and informat are completely incompatible? Will the variable still be displayed?

 

Sorry for asking a weird question...

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

An INFORMAT is used to convert text to values.  Once you have a variable in a SAS dataset the informat attached to the variable is of little value anymore.  It mainly will serve as documentation of how the variable was created.

 

Having an INFORMAT and a FORMAT which share the same name is possible, but does not mean they are compatible or even related.  In real usage it is probably rare that variables would have matching format and informat names anyway, other than the many that should have neither an informat or a format attached..  For most character variables there is no need to attach either an informat or a format.  Similarly for most numeric variables.  Unless you need to represent more than 11 significant digits or want to enforce a fixed number of decimal places on display.  The main need is for DATE, TIME and DATETIME values.  And there it is pretty normal to read the values using one format (or even one of the ANYDTxxx informats) and display with another.

View solution in original post

5 REPLIES 5
Kurt_Bremser
Super User

They can be "incompatible". Think of this: data from Excel was saved incorrectly to a csv, and you have the raw numbers for dates in there. So you read with the informat 5., add '30dec1899'd, and assign the yymmddd10. format to have a SAS date column.

aaronh
Quartz | Level 8
Thank you Kurt. So if I run a proc print, what format or informat will it display?..
Tom
Super User Tom
Super User

@aaronh wrote:
Thank you Kurt. So if I run a proc print, what format or informat will it display?..

It will not print either of them.

 

It will use the FORMAT attached to the variable to determine how to convert the values stored in the variable into the text needed to print.

Kurt_Bremser
Super User

@aaronh wrote:
Thank you Kurt. So if I run a proc print, what format or informat will it display?..

It will not show you the names of the formats, but it will use the assigned format to display the values.

Tom
Super User Tom
Super User

An INFORMAT is used to convert text to values.  Once you have a variable in a SAS dataset the informat attached to the variable is of little value anymore.  It mainly will serve as documentation of how the variable was created.

 

Having an INFORMAT and a FORMAT which share the same name is possible, but does not mean they are compatible or even related.  In real usage it is probably rare that variables would have matching format and informat names anyway, other than the many that should have neither an informat or a format attached..  For most character variables there is no need to attach either an informat or a format.  Similarly for most numeric variables.  Unless you need to represent more than 11 significant digits or want to enforce a fixed number of decimal places on display.  The main need is for DATE, TIME and DATETIME values.  And there it is pretty normal to read the values using one format (or even one of the ANYDTxxx informats) and display with another.

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

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1538 views
  • 3 likes
  • 3 in conversation