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
D
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteB
ReplyDeleteD.Why?
ReplyDeleteD
ReplyDeleteY wud it b D? Where are we getting the extra blank after Ipswich? Could you explain? I think it is B.
ReplyDeleteThe variable length for CITY is the total length for the FIRST variable, which is 16 chars ... there are trailing blanks to the string ..
Deleteie "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 ..
look at the ||, || which includes blank after ","
ReplyDeleteThat means it puts the blank after COMMA (,) not before the comma. The answer is Ipswich, England not Ipswich , England.
ReplyDeletec
ReplyDeletedata work.test;
ReplyDeleteFirst = 'Ipswich, England';
City = substr(First,1,7);
City_Country = City!!', '!!'England';
put City_Country=;
run;
output is :
City_Country=Ipswich , England
Answer is B
ReplyDeleteBecause is there is no trim, there is extra space for city. so answer is D.
ReplyDeleteIf you run in SAS, there is definitely an extra blank after Ipswich before the comma; by POE, it would be D.
ReplyDeleteWhat causes the blank?
ReplyDeletecity 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
ReplyDeletegreat explanation thanks
Deleteans: B
ReplyDeleteExplanation:
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.
To MUNNA:
ReplyDeleteThe 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.
Answer is B
ReplyDeleteIpswich, England
NO.answer is D .i ran program.
ReplyDeleteAnswer is D as the blanks after Ipswich is not produced properly. The answer would look like below: (Assume underscores as blanks)
ReplyDeleteIpswich________, England
Refer to ans for Base SAS 47.
Sakar Sham;
ReplyDeleteI 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
No, because using trim gives the exact same answer. There is something else going on.
Delete"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
ReplyDeleteThis is the reason for trailing blanks after the first word concatenated.
Since the large space occurs after Ipswich, D is the answer.
Answer is Ipswich________, England. There is no answer mentioned with these many spaces the nearest answer would be D
ReplyDeleteIf I try and look at the html result, I got the same as answer D.
ReplyDeleteSo with a 'basic' output, it's Ipswich________, England.
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.
ReplyDeleteExample:
City_Country = City!!', '!!'England' -> "Ipswich__, England"
City_Country = TRIM(City)!!', '!!'England' -> "Ipswich, England"
Answer is D
But substr(first,1,7) should give Ipswich with lenght of 7 , right?
Deleteor do you mean the variable City, when combined with concatenation function, creats with length of 200?
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.
ReplyDeleteExample:
City_Country = City!!', '!!'England' -> "Ipswich__, England"
City_Country = TRIM(City)!!', '!!'England' -> "Ipswich, England"
Answer is D
I suspect, it is not concatenates symbol instead it is exclamatory mark.
ReplyDeleteconcatenation operator can be either double vertical bar (||), broken vertical bar (¦¦), or exclamation mark (!!)
Deletehttp://support.sas.com/documentation/cdl/en/lrcon/62955/HTML/default/viewer.htm#a000780367.htm
ans is D
ReplyDeleteIpswich________, England . TRIM function is used to remove the embedded blanks from the resulting variable */
D
ReplyDeleteNavigate 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
ReplyDeleteDATA WORK.TEST;
ReplyDeleteFIRST = '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??
when i run the code in sas studio it gives B.
ReplyDeleteFirst
City
City_Country
1 lpswich, England lpswich lpswich , England
This comment has been removed by the author.
DeleteI 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.
ReplyDeleteI mean City was created with a length of 16.
Deleteans is D. Look at the output generated in CITY_Country
ReplyDeletethere is a space after Ipswich and after that comes the comma.
(Ipswich , England)---- Ans D
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?
ReplyDeleteThese questions are so hard to answer. So many traps all over the place...
ReplyDeleteD
ReplyDeleteb
ReplyDeleteI tested. The answer is: Ipswich , England
ReplyDeleteCity = substr(First,1,7);
City is 'Ipswich ', the length is the same as First