The following SAS program is submitted: data work.test; Title = 'A Tale of Two Cities, Charles J. Dickens'; Word = scan(title,3,' ,'); run; Which one of the following is the value of the variable WORD in the output data set?
Explanation: the placement of the quotations around the delimiter, the comma, is critical - if there were NO space (','), the value returned would be ' ' (missing character value). However, having the space before the delimiter (' ,') returns the 'of', so it is 'B'
Question :
The following SAS program is submitted: data work.test; First = 'Ipswich, England'; City_Country = substr(First,1,7)!!', '!!'England'; run; Which one of the following is the length of the variable CITY_COUNTRY in the output data set?
Explanation: By default the variable length is determined by the length of the first argument for substr.
So here we have 16 + 2(', ') + 7('England') = 25 In SAS programming, the concatenation operator is a pair of vertical bars (||). If your keyboard does not have a solid vertical bar, use two broken vertical bars (||) or two exclamation points (!!).
The length of the new variable is the sum of the lengths of the pieces or number of characters that is specified in a LENGTH statement for the new variable."
(ref - Sas help and documentation)
Answer is 25 because : length of First = 16 length of ', ' = 2 length of 'England' = 7
Total length = 25. Thus Answer = 4
Question : 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?
Explanation: Because is there is no trim, there is extra space for city. so answer is D. If you run in SAS, there is definitely an extra blank after Ipswich before the comma; by POE, it would be D. Ipswich________, England . TRIM function is used to remove the embedded blanks from the resulting variable.