ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 88

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

29 comments:

  1. Anonymous6:34 AM

    @5 age 2.;

    So B is the Ans:

    Alfr14
    Alic13
    Barb13a (ar)(13)
    Caro14

    ReplyDelete
  2. 'B'
    Answer is
    name age
    "Alfred 14"
    "Alice 13"
    "Barbara 13"
    "Carol 14"

    ReplyDelete
  3. Anonymous3:34 PM

    Can anyone give an explanation why "C" is not right?

    ReplyDelete
  4. Answer 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

    ReplyDelete
  5. Anonymous11:29 AM

    There is no trim/cut and paste applied. BARBARA
    has 7 letter on 5th & 6th sits the age still one more letter from BARBARA available goes at 7th,

    ReplyDelete
  6. Alfr14
    Alic13
    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;

    ReplyDelete
    Replies
    1. Anonymous12:07 PM

      When I tried your code the output is; SAS 9.3 answer seems to be 'D': Am I missing something?

      Name Age
      Alfred 14
      Alice 13
      Barbara 13
      Carol 14

      Delete
    2. 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

      Delete
    3. Anonymous2:43 PM

      I have the same doubt with Anon, anyone can help with please?

      Delete
  7. Anonymous3:44 PM

    The answer is B. Code below- check the log when finished running for what would have been in the file.

    data test;
    input name $ age;
    datalines;
    Alfred 14
    Alice 13
    Barbara 13
    Carol 14
    ;
    data students;
    set test;
    put name $15. @5 age 2.;
    run;

    ReplyDelete
    Replies
    1. I run your code, it came out the result as:
      Obs name age
      1 Alfred 14
      2 Alice 13
      3 Barbara 13
      4 Carol 14

      Delete
    2. Anonymous7:28 PM

      check the log to see PUT statement output not students dataset (using proc print).

      Delete
  8. why there is put instead of input

    ReplyDelete
  9. why there is put instead of input

    ReplyDelete
    Replies
    1. Anonymous7:56 AM

      they are assumed to be formatted correctly. for informat we use input

      Delete
  10. Anonymous7:30 AM

    can some1 explain this again, m new to sas

    ReplyDelete
  11. Anonymous7:32 AM

    I run your code, it came out the result as:
    Obs name age
    1 Alfred 14
    2 Alice 13
    3 Barbara 13
    4 Carol 14

    ReplyDelete
  12. Anonymous7:48 AM

    @5 age2 means at 5th letter of name, 2 numeric values to be put..is it true?

    ReplyDelete
    Replies
    1. Anonymous7:54 AM

      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

      Delete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Just can get why there is an a after the Barb13

    ReplyDelete
  15. data d1;
    infile 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.

    ReplyDelete