The contents of the SAS data set named PERM.STUDENTS are listed below:
name age
Alfred 14
Alice 13
Barbara 13
Carol 14
The following SAS program is submitted using the PERM.STUDENTS data set as input:
libname perm 'SAS-data-library';
data students;
set perm.students;
file 'file-specification';
put name $15. @5 age 2.;
run;
Which one of the following represents the values written to the output raw data file?
A. --------10-------20-------30
Alfred 14
Alice 13
Barbara 13
Carol 14
B. --------10-------20-------30
Alfr14
Alic13
Barb13a
Caro14
C. --------10-------20-------30
Alfr14ed
Alic13e
Barb13ara
Caro14l
D. --------10-------20-------30
Alfred 14
Alice 13
Barbara 13
Carol 14
Click Comment link to get answer
'B'
ReplyDeleteB
ReplyDelete@5 age 2.;
ReplyDeleteSo B is the Ans:
Alfr14
Alic13
Barb13a (ar)(13)
Caro14
'B'
ReplyDeleteAnswer is
name age
"Alfred 14"
"Alice 13"
"Barbara 13"
"Carol 14"
Can anyone give an explanation why "C" is not right?
ReplyDeleteAnswer is B because @5 age 2. will not create space for itself but rather it will overwrite name $15, which is written first. So Alfred written by name variable will become Alfr14
ReplyDeleteI agree.
ReplyDeleteThere is no trim/cut and paste applied. BARBARA
ReplyDeletehas 7 letter on 5th & 6th sits the age still one more letter from BARBARA available goes at 7th,
Alfr14
ReplyDeleteAlic13
Barb13a
Caro14
C is the answer .
Below is the code I tried. Since Name and Age are already in a dataset, they are assumed to be formatted correctly. While put statement is used, since 5th position is mentioned for age, it will write over the name values
data team;
input name $ age;
datalines;
Alfred 14
Alice 13
Barbara 13
Carol 14
;
data students;
set team;
file 'File specification';
put name $15. @5 age 2.;
run;
When I tried your code the output is; SAS 9.3 answer seems to be 'D': Am I missing something?
DeleteName Age
Alfred 14
Alice 13
Barbara 13
Carol 14
Basically whats missing the code above is File path and name in place of " FILE SPECIFICATION" ...we are writing a code to create a raw file , so specify a folder and a name for your file .. eg "C:\Users\someone\Desktop\xyz.txt" and after you run the code open that xyz.txt and see you will see exactly as given in Option B :) ... hope this helps
DeleteI have the same doubt with Anon, anyone can help with please?
DeleteThe answer is B. Code below- check the log when finished running for what would have been in the file.
ReplyDeletedata test;
input name $ age;
datalines;
Alfred 14
Alice 13
Barbara 13
Carol 14
;
data students;
set test;
put name $15. @5 age 2.;
run;
I run your code, it came out the result as:
DeleteObs name age
1 Alfred 14
2 Alice 13
3 Barbara 13
4 Carol 14
check the log to see PUT statement output not students dataset (using proc print).
DeleteB
ReplyDeletewhy there is put instead of input
ReplyDeletewhy there is put instead of input
ReplyDeletethey are assumed to be formatted correctly. for informat we use input
Deletecan some1 explain this again, m new to sas
ReplyDeleteI run your code, it came out the result as:
ReplyDeleteObs name age
1 Alfred 14
2 Alice 13
3 Barbara 13
4 Carol 14
@5 age2 means at 5th letter of name, 2 numeric values to be put..is it true?
ReplyDeletethey are assumed to be formatted correctly. While put statement is used, since 5th position is mentioned for age, it will write over the name values
Deleteb
ReplyDeleteB
ReplyDeleteB
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteJust can get why there is an a after the Barb13
ReplyDeletedata d1;
ReplyDeleteinfile datalines;
input name$ age;
datalines;
Alfred 14
Alice 13
Barbara 13
Carol 14
;
run;
data s1;
set d1;
file print;
put name$ 15. @5 age 2.;
run;
No log error and result is
Alfr14
Alic13
Barb13a
Caro14
answer shouldbe B.