The contents of the raw data file EMPLOYEE are listed below:
--------10-------20-------30
Ruth 39 11 (39 starts at col-7 and 11 at col-10)
Ruth 39 11 (39 starts at col-7 and 11 at col-10)
Jose 32 22
Sue 30 33
John 40 44
The following SAS program is submitted:
data test;
infile 'employee';
input employee_name $ 1-4;
if employee_name = 'Sue' then input age 7-8;
else input idnum 10-11;
run;
infile 'employee';
input employee_name $ 1-4;
if employee_name = 'Sue' then input age 7-8;
else input idnum 10-11;
run;
Which one of the following values does the variable AGE contain when the name of the employee is "Sue"?
A. 30
B. 33
C. 40
D. . (missing numeric value)
A. 30
B. 33
C. 40
D. . (missing numeric value)
7 comments:
Answer: C
data work.TEST;
infile cards;
input employee_name $ 1-4;
if employee_name = 'Sue' then input age 7-8;
else input idnum 10-11;
put _all_;
cards;
Ruth 39 11
Jose 32 22
Sue 30 33
John 40 44
;
run;
employee_name=Ruth age=. idnum=22 _ERROR_=0 _N_=1
employee_name=Sue age=40 idnum=. _ERROR_=0 _N_=2
hi guru,
could u please explain, why is it writing the data like this?
and what should have been the correct statements to get data entered correctly?
The program accepts the name first and the performs the if operation. Since you are not having the @ sign to hold on to the record till for the if condition to be tested, the next input record is read the value of idnum is written as 22 for Ruth and the value of age for Sue is 40. Add the @ sign to hold the record at the input statement.
Eg:
data test;
infile cards;
input employee_name $ 1-4 @;
if employee_name = 'Sue' then input age 7-8;
else input idnum 10-11;
cards;
Ruth 39 11
Jose 32 22
Sue 30 33
John 40 44
;run;
Thanks Mr.V.V Its Great helpful
VV tHANK YOU EXCELLENT SUGGESTION, GREAT HELP
ONE SINGLE TRAILING (@) WILL DO THE MAGIC
thanks VV for this explanation. It seems easy but will make ur mind work. ;)
hi guru,
please explain pdv being formed in each step and how it holds the values in question.
Post a Comment