ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 41

The following SAS program is submitted:
data work.products;
Product_Number = 5461;
Item = '1001';
Item_Reference = Item'/'Product_Number;
run;
Which one of the following is the value of the variable ITEM_REFERENCE in the output data set?
A. 1001/5461
B. 1001/ 5461
C. . (missing numeric value)
D. The value can not be determined as the program fails to execute due to errors.
Click Comment link to get answer

44 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. B is the right answer.
    If we use
    =compress(item||'/'||product_number)
    then the output will be A.

    ReplyDelete
    Replies
    1. Anonymous5:37 PM

      Sorry the ans is D. the program fails to execute due to errors. I just tried it.

      Delete
  3. D.
    since there is no concatenate symbol between them.

    ReplyDelete
    Replies
    1. actualy there is a concatenation symbol, this is not the proper question

      Delete
  4. Anonymous3:07 AM

    D is righ
    133 Item_Reference = Item '/' Product_Number;
    --- --------------
    388 202
    ERROR 388-185: Expecting an arithmetic operator.

    ERROR 202-322: The option or parameter is not recognized and will be ignored.

    ReplyDelete
  5. This comment has been removed by the author.

    ReplyDelete
  6. Anonymous10:09 AM

    concatenating operator is missing.
    Answer is D

    ReplyDelete
  7. Anonymous3:31 PM

    Answer D

    ReplyDelete
  8. Anonymous11:12 PM

    data work.products;
    Product_Number = 5461;
    Item = '1001';
    Item_Reference = Item||'/'||Product_Number;
    run;
    ans is B.

    ReplyDelete
    Replies
    1. (A) Item_Reference = Item'/'Product_Number;
      SAS tries to solve it as an arithmetic operation but quotation
      puzzles SAS as it expects arithmetic operator here

      Ans: D. The value can not be determined as the program fails to execute due to errors.

      (B) Item_Reference = Item/Product_Number;

      Just removing qoutation marks
      Ans: Value of Item_Reference is 0.1832997619

      (C) Item_Reference = Item||'/'||Product_Number;

      Just adding concatenating operator
      Ans : B. 1001/ 5461

      (D) Item_Reference = compress(item||'/'||product_number);
      Item_Reference = Item||'/'||put(Product_Number, 4.);
      Item_Reference = CATX('/',Item,Product_Number);
      Item_Reference = Item||'/'||strip(Product_Number);

      To get the output as given in option A
      Ans: A. 1001/5461

      Delete
  9. Anonymous5:00 PM

    Correct answer is D.

    ReplyDelete
  10. Anonymous8:41 AM

    confusing !!!!!!!!!!!
    wats d right answer....
    & why?

    ReplyDelete
    Replies
    1. the right answer for the question as it is written above is "D" .. because of an error in the code.
      Since this question has come up before (in other question sets) without code errors, readers are assuming a question typing fault .. if the variable are concatenated properly (not as shown above) then there will be some padding and therefore the answer would be "B" in such a case ..
      this is just a very good reminder for all of us to scrutinize the question code very very carefully before committing to an answer (based on similar questions encountered) ... cheers !!

      Delete
  11. Anonymous4:49 PM

    ans should be B.
    for Product_Number Character expected but numerical got, so it automatically change it into Character by using best 12. begining from right.
    So there are 12-4=8 spaces before 5461

    if you put a number which has 12 bytes then there is no space before that number.

    ReplyDelete
  12. Andreas1:51 PM

    correct ans ist D. I tested it.

    ReplyDelete
  13. Anonymous4:03 PM

    Copied : Ans is B and you are right.
    for Product_Number Character expected but numerical got, so it automatically change it into Character by using best 12. beginning from right.
    So there are 12-4=8 spaces before 5461

    if you put a number which has 12 bytes then there is no space before that number.
    How you come with best 12 spaces? Is that default???
    Can you explain it.

    Sakar Sham

    ReplyDelete
    Replies
    1. SAS is automatically converting numeric to character and when it does that the format changes to best12. automatically and the value is right aligned. so there are leading spaces

      Delete
  14. Anonymous12:28 PM

    Man I got sas 9.1 and before I had 9.2, little bit different.
    In this 3 different process I got 3 different answer. One time it gave me product of 0.183299
    once it gave me 1001/ 5461
    and now it is giving me none and answer should be D.
    How to clear the log and out put and submit on 9.1 sas program?

    ReplyDelete
  15. ans is D.... read the question carefully before u ans... / symbol in the 4th line is quoted so the data fails to execute...incase if its not quoted charac variables are changed to numeric and the resulting observation will be 0.1832997619 for variable ITEM_REFERENCE

    ReplyDelete
  16. Answer is D - The program fails to execute.
    -----------------------------------------------

    Log shows:

    430 Item_Reference = Item'/'Product_Number;
    ---
    49
    388
    200
    NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release.
    Inserting white space between a quoted string and the succeeding identifier is
    recommended.

    ERROR 388-185: Expecting an arithmetic operator.

    ERROR 200-322: The symbol is not recognized and will be ignored.
    ----------------------------------------------

    Corrected codes to yield 1001/5461 as output are:

    Code 1:

    data work.products;
    Product_Number = 5461;
    Item = '1001';
    Item_Reference = Item||'/'||put(Product_Number, 4.);
    run;

    Code 2:

    data work.products;
    Product_Number = 5461;
    Item = '1001';
    Item_Reference = CATX('/',Item,Product_Number);
    run;

    ReplyDelete
  17. Anonymous4:28 PM

    B.
    Here you can use the put option to change the numeric to char, but in this example it is not necessary and sas will convert the numeric value to char by default. So we get the output as
    1001/ 5461
    Now, there is a gap after the slash symbol as sas right align numeric variable.

    ReplyDelete
    Replies
    1. Anonymous4:36 PM

      Sorry my explanation is supposed to be the other way round. In this example, sas will do automatic conversion of char variable to numeric. As in the statement
      Item_Reference = input(Item,4.)||'/'||Product_Number
      is done in sas by default.
      So we get 1001/ 5461, with a gap after the slash symbol, as sas right align numeric values

      Delete
    2. good explanation - we get 1001/ 5461 if there is conctenation operator as 5461 i num value and so is right aligned. but with original question; ans is D - does not execute due to errors

      Delete
  18. Answer is B
    Explanation: Numeric formats right-align the result; character formats left-align the result. So 1001/ 5461- (In this case numeric value is falling towards right side) if eg: 26/DP (in this case character value is falling towards left side)

    ReplyDelete
  19. Anonymous2:40 PM

    Answer is D.

    I tested it using this program:
    data ee;
    product_number = 5461;
    item = '1001';
    item_reference = item'/'product_number;
    run;

    proc print data=ee;
    run;

    In the log, I got the error messages: "Expecting an arithmetic operator...The symbol is not recognized and will be ignored...The SAS System stopped processing this step because of errors."

    There was no output from the proc print step. The log read: "No observations in data set WORK.EE."

    ReplyDelete
    Replies
    1. but there are a pair of concatenation operators besides the delimiter
      ought to be
      item_reference=item||'/'||product_number

      Delete
  20. Anonymous9:19 PM

    D
    There is no such thing called automatic converter" So disappointing:D

    ReplyDelete
    Replies
    1. Anonymous9:25 PM

      Ok there is such converter if we try next question... But the converter does not work on this one. I tried and got an error. Answer is still D

      Delete
  21. Anonymous4:43 AM

    Guys, actually the original question contain the concatenation operator

    Item_Reference = Item||'/'||Product_Number

    ReplyDelete
  22. Anonymous1:37 PM

    hello, a side question, the length of the item_reference, I get in sas as 17, could someone please explain the length. I dont know how its 17. please help. thank you in advance.

    ReplyDelete
  23. BBBBBBBBBBBBBBBBB
    try the code below:

    data test;
    Product_Number = 5461;
    Item= '1001';
    Item_Reference = Item!!'/'!!Product_Number;
    run;
    proc print data=test; run;

    ReplyDelete
  24. still confused. item='1001' is a character variable. how can a character variable / a number variable?

    ReplyDelete
  25. Anonymous9:04 PM

    The original question is
    ... Item_Reference=Item||'/'||Product_Number;

    ...
    and the correct answer would be D.

    ReplyDelete
  26. if there are leading spaces then ans should be 1001/ 5461.
    then why there is only one blank

    ReplyDelete
  27. Anonymous6:30 PM

    D is right answer

    ReplyDelete
  28. It's B. I tried it in SAS 9.4. I just copied the program without any change.

    ReplyDelete
  29. Your website is really nice and this is a great inspiring article.

    Gclub จีคลับ
    gclub
    goldenslot

    ReplyDelete
  30. the ans is B, checked it

    data work.products;
    Product_Number = 5461;
    Item = '1001';
    Item_Reference =Item||'/'||Product_Number;
    run;

    output : 1001/ 5461

    data work.products_nospace;
    Product_Number = 5461;
    Item = '1001';
    Item_Reference = compress(Item||'/'||Product_Number);
    run;

    ouput : 1001/5461

    ReplyDelete
  31. Quest Base SAS 41 is Wrong

    Correct is :

    The following SAS program is submitted:
    data work.products;
    Product_Number = 5461;
    Item = '1001';
    Item_Reference = Item || '/' || Product_Number;
    run;

    ReplyDelete