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

Considering the following code,

data belg;
	set belg ;
	days=input(date,10.);
run;

where date is a numeric, 8 length variable with DDMMYY10. as format/informat.

 

When I run it, days values are displayed in the dataset as 3-digits values. Changing the 10. to 12. allows to display the correct SAS date values (5 digits ones). Why do I need to use a 12. informat while the initial variable is DDMMYY10. and the expected variable have 5-length values ? 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

The first parameter to the INPUT function should always be a character string.  But here, you are using a numeric value.  So the question and answer hinge around how SAS handles that situation.

 

SAS takes the numeric value and converts it to character, so that the INPUT function can work.  You would already have received a note on the log about a numeric to character to conversion taking place, but didn't realize the implications.

 

When making a numeric to character conversion, SAS typically uses 12 characters to hold the result.  In this case, that would be 7 blanks, followed by 5 digits.  When you apply the 10. informat to that result, SAS reads 10 characters (7 blanks, plus the first 3 digits).  That's where your 3-digit numbers come from.

View solution in original post

3 REPLIES 3
Astounding
PROC Star

The first parameter to the INPUT function should always be a character string.  But here, you are using a numeric value.  So the question and answer hinge around how SAS handles that situation.

 

SAS takes the numeric value and converts it to character, so that the INPUT function can work.  You would already have received a note on the log about a numeric to character to conversion taking place, but didn't realize the implications.

 

When making a numeric to character conversion, SAS typically uses 12 characters to hold the result.  In this case, that would be 7 blanks, followed by 5 digits.  When you apply the 10. informat to that result, SAS reads 10 characters (7 blanks, plus the first 3 digits).  That's where your 3-digit numbers come from.

Tom
Super User Tom
Super User

What are you trying to actually do?

If the variable has the format MMDDYY10. then it should already have a number of days.  SAS date formats work on numbers that represent the number of days since 1960, with 0 meaning 01JAN1960.

 

Masande
Fluorite | Level 6

I was just trying to manipulate date and conversion. No real objective, just SAS learning. 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 685 views
  • 3 likes
  • 3 in conversation