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
B
ReplyDeleteCorrect Ans: C
ReplyDeleteC
ReplyDeleteC
ReplyDeleteObs name age height
1 John . 35
2 June . 10
3 Tineke . 9
Numeric missing values are treated as extremely small negative numbers.
ReplyDeleteAnswer C for sure
ReplyDeleteCorrect 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.
ReplyDeletethats a data error and not a syntax error so it executes
DeleteYou are correct but still executes the pgm
DeleteC
ReplyDeletesas can still read the observations, just not correctly.
Answer C. SAS will read the three observation but not correctly. Please run the blow program and check.
ReplyDeletedata 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;
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.
ReplyDeletetry 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;
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.
ReplyDeleteThis is incorrect since there is not output using the condition 'if age GE 10;'
DeleteC
ReplyDeleteThis 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
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.
DeleteThese are not syntax errors but notes generated at run time. If it was syntax error then there will not be any observations.
ReplyDeleteHow about the unclosed If statement?
ReplyDeleteanswer should be A
Name variable has first name and last name.
ReplyDeleteIn 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
Thanks, we can not run the program in test and answer it correctly. Unless you we com with the reasons.
ReplyDeleteIf 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.
The correct explanation:
ReplyDeleteThe 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
This is incorrect since the if statement does work with the condition:
Deleteif age GE 10;
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...
ReplyDeletesupport.sas.com/documentation/cdl/en/lrcon/62753/HTML/default/viewer.htm#n1il1j711miuhrn1tp0pldybc6zq.htm
data work.homework;
ReplyDeleteinfile '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
So An s : C
ReplyDeletehow to understand the ans is C in exam coz we cannot run the problem there?
ReplyDeleteit 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
ReplyDeleteans 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.
ReplyDeleteI think this might clear the concept to an extent.-nk
Thank you :)
DeleteData homewo;
ReplyDeleteinput 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
Are these questions on the exam? Or are they similar? If so, how similar?
ReplyDeleteAns:C
ReplyDeleteSpace 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
C
ReplyDeleteDear this is B Only :) Proof executed by Mr. Srivatsan
ReplyDeletec executed and tested
ReplyDelete1 John . 35
ReplyDelete2 June . 10
3 Tineke . 9
this is the correct answer when executed
DeleteThe if statement considers a missing numeric value as smaller than any other numeric value. It's simply a convention used by SAS.
ReplyDeletehttp://support.sas.com/documentation/cdl/en/lrcon/65287/HTML/default/viewer.htm#p0tmoipp0ci6wkn0z27ev47sv0ov.htm