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

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 ?

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

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

View solution in original post

6 REPLIES 6
Sanyam
Calcite | Level 5

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

Kurt_Bremser
Super User

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

Sanyam
Calcite | Level 5

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.

Kurt_Bremser
Super User

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.

Sanyam
Calcite | Level 5

Thanks Kurt.

I completely misjudged it and didn't think it that it was a 'Column Input'.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 2031 views
  • 3 likes
  • 2 in conversation