How does the variable weight has the value 2 in the following example?
Example :
data test;
input @1 height 2. @4 weight 2;
datalines;
72 95
;
Output:
Height Weight
72 2
Is there any special usage of formatted input when there is no period in the numeric informat ?
Since "1" or "2" is not a format, but a value, and follows a variable name, it is interpreted by the input statement as a column. Therefore you read the contents of columns 2 and 1, respectively, which happen to be 2 and 7.
An "informat" without a dot is not an informat, it is ALWAYS something else.
The only time you write a format/informat name without a dot is when specifying it in proc format at creation time.
Edited a typo
"2" is not a format, it is a value. "2." is a format. A format MUST be called with a dot.
Kurt,
It is correct that we must use informat with a dot/period.
But I need to know how SAS works behind the scenes when the informat is without a dot or how the column pointer moves in that case.
As an alternative to the above example, if I use 1 instead of 2 then the output value for variable weight is 7.
Example :
data test;
input @1 height 2. @4 weight 1;
datalines;
72 95
;
Output:
Height Weight
72 7
Since "1" or "2" is not a format, but a value, and follows a variable name, it is interpreted by the input statement as a column. Therefore you read the contents of columns 2 and 1, respectively, which happen to be 2 and 7.
An "informat" without a dot is not an informat, it is ALWAYS something else.
The only time you write a format/informat name without a dot is when specifying it in proc format at creation time.
Edited a typo
Thanks Kurt, I got the point that it reads at the value particular column.
Also, I am curious to know why SAS does this unexpected thing and also doesn't show any NOTE in SAS log.
It is not unexpected behaviour, just see the SAS documentation for the input statement:
SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition
Go to "Input Styles - Column Input".
Since it can do what the code told it to do without problems, SAS sees no need for NOTE, WARNING or ERROR messages.
Thanks Kurt.
I completely misjudged it and didn't think it that it was a 'Column Input'.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.