- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi All.
I am new to SAS and started exploring.
I am bit confused with using PUT and INPUT, please help me.
I have a column named Birth_date of type numeric and length 8 Format and Informat MMDDYY10.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
When SAS is instructed to perform an operation on a character string, but the value fed to that operation is numeric, SAS has to perform a numeric-to-character conversion.
Most of the time, SAS generates a 12-character-long string. So if the numeric value coming in is 3.14, SAS converts this to 8 blanks, followed by the characters "3.14". The conversion process right-hand justifies the original numeric value within the 12-character-long string.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Super User @MichelleHomes has shared a really useful blog post about PUT and INPUT and how to remember the difference.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Birth date is already a SAS date.
Insread of PUT/INPUT apply a FORMAT statememt.
Format birth_date DATE9.;
. This section of the SAS documentation covers SAS dates quite thoroughly.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
To answer the "why" questions, you have to begin by understanding how SAS stores dates. That number (2199) means that January 8, 1966 falls 2199 days after January 1, 1960. That's how SAS expects to store dates, and why Reeza's reply will give you part of the answer to your questions.
The other part of the "why" questions concerns the INPUT function. INPUT expects to see a character string as the first argument, and reads that character string using the instructions within the second argument. Here, you are passing a number as the first argument. That forces SAS to perform a numeric-to-character conversion to be able to apply the INPUT function. (You might have noticed a message about conversion in the log.) And when SAS performs a numeric-to-character conversion, the usual method it applies is to use a 12-character field, right-hand justified. So the INPUT function is actually reading 8 blanks, followed by "2199". If you apply instructions that tell the INPUT function to read only 10 characters, it finds 8 blanks plus "21".
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi
Thanks for replying, it really helps me a lot.
Could you please explain the below statement, i could not able to get this.
"And when SAS performs a numeric-to-character conversion, the usual method it applies is to use a 12-character field, right-hand justified. So the INPUT function is actually reading 8 blanks, followed by "2199". If you apply instructions that tell the INPUT function to read only 10 characters, it finds 8 blanks plus "21".
Thanks & Regards
Vishyy
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
When SAS is instructed to perform an operation on a character string, but the value fed to that operation is numeric, SAS has to perform a numeric-to-character conversion.
Most of the time, SAS generates a 12-character-long string. So if the numeric value coming in is 3.14, SAS converts this to 8 blanks, followed by the characters "3.14". The conversion process right-hand justifies the original numeric value within the 12-character-long string.