ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 81

A raw data file is listed below:
--------10-------20-------30
John McCloskey 35 71
June Rosesette 10 43
Tineke Jones 9 37
The following SAS program is submitted using the raw data file as input:
data work.homework;
infile 'file-specification';
input name $ age height;
if age LE 10;
run;
How many observations will the WORK.HOMEWORK data set contain?
A. 0
B. 2
C. 3
D. No data set is created as the program fails to execute due to errors.
Click Comment link to get answer

38 comments:

  1. Anonymous5:35 AM

    C
    Obs name age height
    1 John . 35
    2 June . 10
    3 Tineke . 9

    ReplyDelete
  2. Anonymous9:59 PM

    Numeric missing values are treated as extremely small negative numbers.

    ReplyDelete
  3. Anonymous9:12 AM

    Answer C for sure

    ReplyDelete
  4. Anonymous1:36 PM

    Correct ans is D, Coz there is a space between first name and last name so age read as character value and peogram terminate with error.

    ReplyDelete
    Replies
    1. Anonymous2:08 AM

      thats a data error and not a syntax error so it executes

      Delete
    2. You are correct but still executes the pgm

      Delete
  5. Anonymous10:42 PM

    C

    sas can still read the observations, just not correctly.

    ReplyDelete
  6. Answer C. SAS will read the three observation but not correctly. Please run the blow program and check.
    data work.homework;
    infile datalines;
    input name $ age height;
    if age LE 10;
    datalines;
    John McCloskey 35 71
    June Rosesette 10 43
    Tineke Jones 9 37
    ;
    run;

    ReplyDelete
  7. Anonymous12:51 AM

    The name has a blank in it so we need to use the & list modifier to read the data, also when using this we have to make sure that the data are atleast two spaces apart.
    try to work this out:

    data work.homework;
    infile datalines;
    input name & $15. age height;
    if age LE 10;
    datalines;
    John McCloskey 35 71
    June Rosesette 10 43
    Tineke Jones 9 37
    ;
    run;
    proc print;
    run;

    ReplyDelete
  8. Anonymous4:08 PM

    Also, the point to be noted is that IF condition will not be applied bcz values of AGE variables are missing due to absence of &. So, we get all 3 observations.

    ReplyDelete
    Replies
    1. Anonymous2:47 AM

      This is incorrect since there is not output using the condition 'if age GE 10;'

      Delete
  9. Anonymous2:16 PM

    C
    This is the log window:

    113 data work.homework;
    114 infile datalines;
    115 input name $ age height;
    116 if age LE 10;
    117 datalines;

    NOTE: Invalid data for age in line 118 6-14.
    RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+---
    118 John McCloskey 35 71
    name=John age=. height=35 _ERROR_=1 _N_=1
    NOTE: Invalid data for age in line 119 6-14.
    119 June Rosesette 10 43
    name=June age=. height=10 _ERROR_=1 _N_=2
    NOTE: Invalid data for age in line 120 8-12.
    120 Tineke Jones 9 37
    name=Tineke age=. height=9 _ERROR_=1 _N_=3
    NOTE: The data set WORK.HOMEWORK has 3 observations and 3 variables.
    NOTE: DATA statement used (Total process time):
    real time 0.04 seconds
    cpu time 0.01 seconds


    121 ;
    122 run;

    Inspite of the error msges, dataset is created wid 3 obs:
    Obs name age height
    1 John . 35
    2 June . 10
    3 Tineke . 9

    ReplyDelete
    Replies
    1. Anonymous9:33 AM

      data entry by datalines is not processed the same way as with a raw data file. For the raw data file, it is delimited by space, thus SAS reads new variable after each delimiter is encountered.

      Delete
  10. Anonymous2:38 PM

    These are not syntax errors but notes generated at run time. If it was syntax error then there will not be any observations.

    ReplyDelete
  11. How about the unclosed If statement?
    answer should be A

    ReplyDelete
  12. Anonymous12:52 PM

    Name variable has first name and last name.
    In input we had only name $ and no line pointer therefore it takes the first name as name and takes the family name as age, but family name is character variable it will be looking numeric value therefore it treats as missing variable then as height it will take 35 in the first observation
    Results is as follows inspite of error message in log.
    Obs name age height
    1 John . 35
    2 June . 10
    3 Tineke . 9

    ReplyDelete
  13. Anonymous10:19 AM

    Thanks, we can not run the program in test and answer it correctly. Unless you we com with the reasons.
    If we do not think as last commenter did, I was thinking of choosing two observations where age le 10 and almost forgot the last name is not in the input or the column pointer to be a single variable.
    I was thinking as in the input we have name $ , age height. And SAS program will look at the next field which is numeric and will take first name and last name together and will have 2 observation to full fill the age<= 10.
    Thanks all.

    ReplyDelete
  14. Anonymous11:51 AM

    The correct explanation:
    The data set homework will have missing values under the age variable[because of non specification of field eg. input @1 name $ 1-14 @16 age @19 height;in the input statement].

    As a result the if statement will not be evaluated. and all three observation will remain in the data set. SO RIGHT ANS IS C.

    EXTRA KNOWLEDGE:
    BUT IF YOU RUN THE BELOW CODE
    data work.homework1;
    infile datalines;
    input @1 name $ 1-14 @16 age @19 height;
    if age LE 10;
    datalines;
    John McCloskey 35 71
    June Rosesette 10 43
    Tineke Jones 9 37
    ;
    run;
    you will get 2 observation ,,,,becoz if statement will be evaluated

    email:

    debaraj27@gmail.com

    ReplyDelete
    Replies
    1. Anonymous2:52 AM

      This is incorrect since the if statement does work with the condition:

      if age GE 10;

      Delete
  15. Anonymous2:11 PM

    The correct answer is C not because if statement is not executed, but just because missing numeric values are smaller than all other numeric values. Follow this link for more...
    support.sas.com/documentation/cdl/en/lrcon/62753/HTML/default/viewer.htm#n1il1j711miuhrn1tp0pldybc6zq.htm

    ReplyDelete
  16. data work.homework;
    infile 'G:\zaksas\Application\day01\sasfiles\info.txt';
    input name $ age height;
    if age LE 10;
    run;

    LOG:


    168
    169 data work.homework;
    170 infile 'G:\zaksas\Application\day01\sasfiles\info.txt';
    171 input name $ age height;
    172 if age LE 10;
    173 run;

    NOTE: The infile 'G:\zaksas\Application\day01\sasfiles\info.txt' is:
    File Name=G:\zaksas\Application\day01\sasfiles\info.txt,
    RECFM=V,LRECL=256

    NOTE: Invalid data for age in line 1 6-14.
    RULE: ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9--
    1 John McCloskey 35 71 20
    name=John age=. height=35 _ERROR_=1 _N_=1
    NOTE: Invalid data for age in line 2 6-14.
    2 June Rosesette 10 43 20
    name=June age=. height=10 _ERROR_=1 _N_=2
    NOTE: Invalid data for age in line 3 8-12.
    3 Tineke Jones 9 37 17
    name=Tineke age=. height=9 _ERROR_=1 _N_=3
    NOTE: 3 records were read from the infile 'G:\zaksas\Application\day01\sasfiles\info.txt'.
    The minimum record length was 17.
    The maximum record length was 20.
    NOTE: The data set WORK.HOMEWORK has 3 observations and 3 variables.
    NOTE: DATA statement used (Total process time):
    real time 0.04 seconds
    cpu time 0.01 seconds

    OUTPUT :

    Obs name age height
    1 John . 35
    2 June . 10
    3 Tineke . 9

    ReplyDelete
  17. how to understand the ans is C in exam coz we cannot run the problem there?

    ReplyDelete
  18. Anonymous11:34 PM

    it is used list input method to read the data from raw data file. It reads up to next Space found. Either it should have used column input method to read required fields. or should have enclosed in quotation for space embedded. other answers can not be considered as correct one.- nk

    ReplyDelete
  19. Anonymous6:59 PM

    ans is c bcoz when list input method is used, it reads upto next blank. since second variable is numeric ie age but sas can't find it as numeric but character. Hence allocates missing value in pdv for second variable. When pointer moves to read next non missing value for the third variable is the second variable ie age. Hence age as read as ht. Since there are no values in the age variable , sas considers it as a smallest value. So we get 3 observation in output dataset. Though the log indicates invalid data for age.

    I think this might clear the concept to an extent.-nk

    ReplyDelete
  20. Data homewo;
    input fname$ lname $ age height;
    if age LE 10;
    datalines;
    John McCloskey 35 71
    June Rosesette 10 43
    Tineke Jones 9 37
    sw singh . 67
    ;
    run
    with given prg code, ans is C but if i add 4th obs and change code for fname and lname etc then 3 obs, even missing come sin age le 9. hope it helps

    ReplyDelete
  21. Anonymous12:24 AM

    Are these questions on the exam? Or are they similar? If so, how similar?

    ReplyDelete
  22. Ans:C

    Space in observation 'John McCloskey' makes SAS think that the value for age is McCloskey and since its not a numeric a missing entry is placed in the ouput thus missing <=10 returns true and all three observation are passed to data set

    ReplyDelete
  23. Anonymous7:42 AM

    Dear this is B Only :) Proof executed by Mr. Srivatsan

    ReplyDelete
  24. Anonymous9:22 PM

    c executed and tested

    ReplyDelete
  25. Anonymous9:23 PM

    1 John . 35
    2 June . 10
    3 Tineke . 9

    ReplyDelete
    Replies
    1. Anonymous9:24 PM

      this is the correct answer when executed

      Delete
  26. Anonymous2:56 AM

    The if statement considers a missing numeric value as smaller than any other numeric value. It's simply a convention used by SAS.

    http://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p0tmoipp0ci6wkn0z27ev47sv0ov.htm

    ReplyDelete