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.
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.
Super User @MichelleHomes has shared a really useful blog post about PUT and INPUT and how to remember the difference.
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.
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".
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
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.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.