ElearnSAS.com

ElearnSAS.com
SAS Learning Platform

Base SAS 48

The following SAS program is submitted:
data work.test;
First = 'Ipswich, England';
City = substr(First,1,7);
City_Country = City!!', '!!'England';
run;
Which one of the following is the value of the variable CITY_COUNTRY in the output data set?
A. Ipswich!!
B. Ipswich, England
C. Ipswich, 'England'
D. Ipswich , England
Click Comment link to get answer

47 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Anonymous10:52 AM

    Y wud it b D? Where are we getting the extra blank after Ipswich? Could you explain? I think it is B.

    ReplyDelete
    Replies
    1. The variable length for CITY is the total length for the FIRST variable, which is 16 chars ... there are trailing blanks to the string ..
      ie "Ipswich_________" ... so there will be padding ... you need to use the right() function or trim() or strip() to remove the trailing blanks at the time of concatenation ..

      Delete
  3. Anonymous1:02 PM

    look at the ||, || which includes blank after ","

    ReplyDelete
  4. Anonymous8:55 PM

    That means it puts the blank after COMMA (,) not before the comma. The answer is Ipswich, England not Ipswich , England.

    ReplyDelete
  5. data work.test;
    First = 'Ipswich, England';
    City = substr(First,1,7);
    City_Country = City!!', '!!'England';
    put City_Country=;
    run;

    output is :
    City_Country=Ipswich , England

    ReplyDelete
  6. Anonymous9:28 AM

    Answer is B

    ReplyDelete
  7. Because is there is no trim, there is extra space for city. so answer is D.

    ReplyDelete
  8. Anonymous6:20 AM

    If you run in SAS, there is definitely an extra blank after Ipswich before the comma; by POE, it would be D.

    ReplyDelete
  9. Anonymous6:04 AM

    What causes the blank?

    ReplyDelete
  10. Anonymous7:40 PM

    city has the same length with First,the length is 16,the letter of city is first 7 letter of first,the rest 9 digit is fix with blank,so D

    ReplyDelete
  11. ans: B
    Explanation:
    First = 'Ipswich, England';
    City = substr(First,1,7);
    now City having the value Ipswich.Wht is substr will do..read the variable value from 1st position to 7 characters.So the City should b Ipswich.

    City_Country = City!!', '!!'England'

    now City immediately concatiante with ', '(comma and one space) and England(Character).

    so ans is Ipswich, England
    means ans is B.
    MUNNA.

    ReplyDelete
  12. Anonymous3:57 PM

    To MUNNA:
    The length for City would be the length for 'Ipswich, England' which will be 16, it will form some blank spaces in City_Country after concatenating.

    ReplyDelete
  13. Answer is B
    Ipswich, England

    ReplyDelete
  14. Anonymous11:45 AM

    NO.answer is D .i ran program.

    ReplyDelete
  15. Anonymous12:31 AM

    Answer is D as the blanks after Ipswich is not produced properly. The answer would look like below: (Assume underscores as blanks)

    Ipswich________, England

    Refer to ans for Base SAS 47.

    ReplyDelete
  16. Anonymous4:55 PM

    Sakar Sham;

    I think it is same as with the other one it has cut and pasted
    16 + 2 + 7 = 25.
    again the cut = 7 space is still there and not going to trim unless we use "TRIM", that 7 cut space will be in the out put like this.
    Ipswich________, England but in the
    and which is D.
    Do you agree on my point?
    Sham

    ReplyDelete
    Replies
    1. Anonymous3:31 PM

      No, because using trim gives the exact same answer. There is something else going on.

      Delete
  17. "When a character value is shorter than the length of the variable to which it belongs, SAS pads the value with trailing blanks. " - Sas help and documentation

    This is the reason for trailing blanks after the first word concatenated.

    Since the large space occurs after Ipswich, D is the answer.

    ReplyDelete
  18. Answer is Ipswich________, England. There is no answer mentioned with these many spaces the nearest answer would be D

    ReplyDelete
  19. Guillaume8:01 PM

    If I try and look at the html result, I got the same as answer D.

    So with a 'basic' output, it's Ipswich________, England.

    ReplyDelete
  20. The new variable City is creating with length 200. When I concatenate variable City with text 'England' are add blank spaces left comma. Why I don't use TRIM function.
    Example:

    City_Country = City!!', '!!'England' -> "Ipswich__, England"
    City_Country = TRIM(City)!!', '!!'England' -> "Ipswich, England"

    Answer is D

    ReplyDelete
    Replies
    1. Anonymous7:08 AM

      But substr(first,1,7) should give Ipswich with lenght of 7 , right?
      or do you mean the variable City, when combined with concatenation function, creats with length of 200?

      Delete
  21. The new variable City is creating with length 200. When I concatenate variable City with text 'England' are add blank spaces left comma. Why I don't use TRIM function.
    Example:

    City_Country = City!!', '!!'England' -> "Ipswich__, England"
    City_Country = TRIM(City)!!', '!!'England' -> "Ipswich, England"

    Answer is D

    ReplyDelete
  22. Anonymous10:12 PM

    I suspect, it is not concatenates symbol instead it is exclamatory mark.

    ReplyDelete
    Replies
    1. Anonymous10:14 AM

      concatenation operator can be either double vertical bar (||), broken vertical bar (¦¦), or exclamation mark (!!)
      http://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780367.htm

      Delete
  23. Meenal4:50 PM

    ans is D
    Ipswich________, England . TRIM function is used to remove the embedded blanks from the resulting variable */

    ReplyDelete
  24. Navigate the site pages for more questions and answers. So go ahead, it's time to take your drug and alcohol test so you can get your license. Cdl Test Answers

    ReplyDelete
  25. Anonymous12:57 PM

    DATA WORK.TEST;
    FIRST = 'Ipswich, England';
    CITY = SUBSTR(FIRST,1,7);
    CITY_COUNTRY = CITY!!', '!!'England';
    CITY_COUNTRY_2 = SUBSTR(FIRST, 1, 7)!!', '!!'England';
    RUN;

    PROC PRINT DATA=TEST; RUN;

    The results:
    CITY_COUNTRY CITY_COUNTRY_2
    Ipswich , England Ipswich, England

    WHY??

    ReplyDelete
  26. Anonymous9:51 PM

    when i run the code in sas studio it gives B.

    ReplyDelete
  27. Anonymous9:52 PM


    First
    City
    City_Country
    1 lpswich, England lpswich lpswich , England

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  28. Anonymous8:02 PM

    I ran the program. City_country was created with a length of 16. My guess is that SAS compiler is not intelligent enough to know that our intention is for it to have the exact length of the substring. It just uses the length of the original string as the length of the new variable. Space padding is ensued. So the answer D.

    ReplyDelete
    Replies
    1. Anonymous8:04 PM

      I mean City was created with a length of 16.

      Delete
  29. ans is D. Look at the output generated in CITY_Country
    there is a space after Ipswich and after that comes the comma.
    (Ipswich , England)---- Ans D

    ReplyDelete
  30. Anonymous3:51 PM

    I ran the code and it gave B. it makes sense to me that there should be trailing blanks after Ipswich as the total length of City_Country is still 25. However the output still agrees with B. can someone plz verify which answer it should be?

    ReplyDelete
  31. Anonymous11:50 PM

    These questions are so hard to answer. So many traps all over the place...

    ReplyDelete
  32. Walter592810:48 PM

    I tested. The answer is: Ipswich , England

    City = substr(First,1,7);
    City is 'Ipswich ', the length is the same as First

    ReplyDelete