Base SAS 13

The contents of the raw data file SIZE are listed below:
--------10-------20-------30
72 95
The following SAS program is submitted:
data test;
infile 'size';
input @1 height 2. @4 weight 2;
run;
Which one of the following is the value of the variable WEIGHT in the output data set?
A. 2
B. 72
C. 95
D. . (missing numeric value)
Click Comment link to get answer

18 comments:

  1. The answer is A

    ReplyDelete
  2. Ans A;

    Since there is no period after weight2(weight2.) the pointer will move to column 2

    ReplyDelete
  3. The answer is D i.e Missing Value. As the period is missing, the length of the variable is assigned as 2 and a missing value is assigned as SAS is unable to read the value using the specified informat.

    ReplyDelete
  4. Answer is A.....as the weight has no dot after 2 it moves to the pointer to column 2.

    ReplyDelete
  5. D is correct ...because of invalid informat of weight

    ReplyDelete
  6. The answer is A. Since the 2. is not specified correctly, it considers 2 as column input and moves the pointer to column 2.
    also remember, if you just specified @4 weight;
    it would still be ok and it will give the correct value 95.

    ReplyDelete
  7. Answer A not D,just tried it

    ReplyDelete
  8. Answer is D , Just tried it and as per the SAS online document, any variable declared without proper informat will produce a missing value, a '.' for numeric ans space for character .

    ReplyDelete
  9. answer is A.

    ReplyDelete
  10. anonymous is Ans A only...

    ReplyDelete
  11. just tried, ans is A (the pointer moves to the 2nd column)

    ReplyDelete
  12. If Answer is A, can you give us the logic to support it. Why pointer moves to 2nd column?

    sakar

    ReplyDelete
  13. Sakar. I got my sas program and ran it differently;
    data test;
    input @ 1 height 2 @ 4 weight 2 ;
    cards;
    72 95
    ;

    run;
    Log:There were 1 observations read from the data set WORK.TEST.
    output;
    Obs height weight

    1 2 2

    Look the mistry I found is if put dot sign gives different answer.
    data test;
    input @ 1 height 2. @ 4 weight 2. ;
    cards;
    72 95
    ;
    OUTPUT.
    Obs height weight

    1 72 95

    I DO NOT HAVE THE LOGIC BEHIND IT AND MAY BE SOMEBODY CAN EXPLAIN IT. WHY THAT DOT MAKES DIFFERENT.
    I GUESS IF YOU HAVE A COLUMN INPUT STATEMENT LIKE THIS.
    INPUT @ 1 HEIGHT 2. $4 WEIGHT 5 ;
    IT MISLEADS THE LOGIC AND PUT THE 5 WITHOUT DOT AFTER 5 ( 5.) IT MAY NOT BE ASKING TO TAKE 5 SPACE OR WIDTH AFTER BUT PUT 5
    Let us know what it is.

    ReplyDelete
  14. I got the answer sakar.

    input @ 1 height 2 @ 4 weight 4;
    cards;
    72 95
    ;

    In this case the @4 it will put the value from the column 4 which is 9. So to assign 2 space we must add 2. or if we want to assign 3 space it should be 3.

    ReplyDelete
  15. I think the answer should be D. I reffered the book and it says when using formatted input if we forget to add period (.) after the value it assigns it that length for the variable.
    "Remember to specify the period in the informat name. For example, if you omit the period in the following INPUT statement, SAS assigns a length of 3 to JobTitle instead of reading JobTitle with the 3. informat.
    input @9 FirstName $5. @1 LastName $7. +7 JobTitle 3;"
    Please correct me if iam wrong..

    ReplyDelete