由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - SAS BASE 快疯掉了!!!!
相关主题
#SAS BASE 问题,明天就考试了##百思不得其解的sas base 123题第76题
SAS BASE的一道题不明白,青椒帮忙看一道题
base 123题第72/73题求解:关于substr的返回长度还问道SAS的题目
another sas question[合集] 请教sas base 123中几题
a question about length assignment请教两道SAS变量长度的题目
再问三个关于length的问题,谢谢发现sas base123 有几个错误的地方
弱问:一道BASE题,怎么也不明白请教SAS 123题中的17, 57, 68, 72题
SAS base string questiona problem from sas base test
相关话题的讨论汇总
话题: city话题: country话题: length话题: first话题: substr
进入Statistics版参与讨论
1 (共1页)
t*****2
发帖数: 94
1
QUESTION 72
The following SAS program is submitted:
data work.test;
First='Ipswich, England';
City=substr(First,1,7);
City_Country=City ||', '||'England';
run;
L1= length(City_Country);
L2= lengthc(City_Country);
答案是: L1=25, L2=25
但是把程序改成如下:
City_Country=substr(First,1,7)||', '||'England';
L1= length(City_Country);
L2= lengthc(City_Country);
答案是:L1=16, L2=25
我就怀疑有trailing, 所以试了newname=trim(City_Country);但是长度还是25.我就搞
不清楚这个16是什么情况。
我快疯掉了。帮帮忙!
o*******w
发帖数: 2310
2
City=substr(First,1,7)
the city will have the same length as First=16 because of the substr;
the substr(First,1,7)=7 bytes so City_Country=substr(First,1,7)||', '||'
England'has length 7+1+8=16.
d******9
发帖数: 404
3
Pat pat.... The difference is if you create a new variable or not.
In the Case 1,
First='Ipswich, England';
City=substr(First,1,7);
City_Country=City ||', '||'England';
The results of SUBSTR function is assigned to the newly created variable
city, therefore the length of city is 16, same as First by default.
Thus, the length of City_Country is: 16 + 2 + 7=25.
In Case 2, you did not create a new variable when use SUBSTR,
City_Country=substr(First,1,7)||', '||'England';
Thus, the length of City_Country is: 7 + 2 + 7= 16.
BAO ZI, please
o*******w
发帖数: 2310
4
good!

【在 d******9 的大作中提到】
: Pat pat.... The difference is if you create a new variable or not.
: In the Case 1,
: First='Ipswich, England';
: City=substr(First,1,7);
: City_Country=City ||', '||'England';
: The results of SUBSTR function is assigned to the newly created variable
: city, therefore the length of city is 16, same as First by default.
: Thus, the length of City_Country is: 16 + 2 + 7=25.
: In Case 2, you did not create a new variable when use SUBSTR,
: City_Country=substr(First,1,7)||', '||'England';

o*******w
发帖数: 2310
5
what is your test date?

【在 t*****2 的大作中提到】
: QUESTION 72
: The following SAS program is submitted:
: data work.test;
: First='Ipswich, England';
: City=substr(First,1,7);
: City_Country=City ||', '||'England';
: run;
: L1= length(City_Country);
: L2= lengthc(City_Country);
: 答案是: L1=25, L2=25

d******9
发帖数: 404
6
Sorry, I was wrong.
The true reason is because of the below notes from SAS support:
Comparisons
*
The LENGTHC function returns the length of a character string,
including trailing blanks, whereas the LENGTH and LENGTHN functions return
the length of a character string, excluding trailing blanks. LENGTHC always
returns a value that is greater than or equal to the value of LENGTHN.
*
The LENGTHC function returns the length of a character string,
including trailing blanks, whereas the LENGTHM function returns the amount
of memory in bytes that is allocated for a character string. For fixed-
length character strings, LENGTHC and LENGTHM always return the same value.
For varying-length character strings, LENGTHC always returns a value that is
less than or equal to the value returned by LENGTHM.
----------------------------
Try to run below codes:
data S;
A='abcde12345';
X=substr(A, 1, 3);
Y=X||'XYZ';
Z=substr(A, 1, 3)|| 'XYZ';
L1=length(X);
L2=length(Y);
run;
You will find that:
Y='abc#######XYZ';
Z='abcXYZ#######';
# represents blank spaces.
The differences arise from the positions of these padded blanks, although they have same lengths. Then when you use LENGTH function, it will make a difference..
o*******w
发帖数: 2310
7
Obs A X Y Z L1 L2
1 abcde12345 abc abc XYZ abcXYZ 13 6
Z have 6 bytes, no spaces at all.

always

【在 d******9 的大作中提到】
: Sorry, I was wrong.
: The true reason is because of the below notes from SAS support:
: Comparisons
: *
: The LENGTHC function returns the length of a character string,
: including trailing blanks, whereas the LENGTH and LENGTHN functions return
: the length of a character string, excluding trailing blanks. LENGTHC always
: returns a value that is greater than or equal to the value of LENGTHN.
: *
: The LENGTHC function returns the length of a character string,

o*******w
发帖数: 2310
8
So, how to explain the 13 in L2? where is the 7 blank spaces from?
data S;
A='abcde12345';
X=substr(A, 1, 3);
Y=X||'XYZ';
Z=substr(A, 1, 3)|| 'XYZ';
L1=length(y);
L2=lengthc(z);
run;
proc print;
run;
Obs A X Y Z L1
L2
1 abcde12345 abc abc XYZ abcXYZ 13 13
d******9
发帖数: 404
9
Yes, this is the SAS output.
L2=6 because when you use LENGH function, it does not count the trailing
blanks in Z.
But for Y, the 7 blanks are in the middle of Y, so they really counts and L1
=13.
However, if you view the column properties, it will show that the lengths of
both Y and Z are both 13.

【在 o*******w 的大作中提到】
: So, how to explain the 13 in L2? where is the 7 blank spaces from?
: data S;
: A='abcde12345';
: X=substr(A, 1, 3);
: Y=X||'XYZ';
: Z=substr(A, 1, 3)|| 'XYZ';
: L1=length(y);
: L2=lengthc(z);
: run;
: proc print;

o*******w
发帖数: 2310
10
Base SAS 47
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?
A. 6
B. 7
C. 17
D. 25
Base SAS 48
The following SAS program is submitted:
data work.test;
SAS Base Certification Page 16 of 83
http://sascert.blogspot.com/search?updated-min=2006-01-01T00:00 12/22/2011
22 comments Links to this post
Reactions:
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

【在 t*****2 的大作中提到】
: QUESTION 72
: The following SAS program is submitted:
: data work.test;
: First='Ipswich, England';
: City=substr(First,1,7);
: City_Country=City ||', '||'England';
: run;
: L1= length(City_Country);
: L2= lengthc(City_Country);
: 答案是: L1=25, L2=25

相关主题
再问三个关于length的问题,谢谢百思不得其解的sas base 123题第76题
弱问:一道BASE题,怎么也不明白帮忙看一道题
SAS base string question还问道SAS的题目
进入Statistics版参与讨论
o*******w
发帖数: 2310
11
Therefore, the correct answer is:
No matter what, the substr() result will have a data keep the original
variable's length by adding blank spaces before or after.
d******9
发帖数: 404
12
Yes. Exactly, this is the default !
But when you use LENGTH function to check the following concatenated
variables, the values may be different. Be careful !

【在 o*******w 的大作中提到】
: Therefore, the correct answer is:
: No matter what, the substr() result will have a data keep the original
: variable's length by adding blank spaces before or after.

t*****2
发帖数: 94
13
没有解决我的问题呀。我知道长度怎么来的。问题的关键是:
City_Country=substr(First,1,7)||', '||'England';
7+2+7=16
但是LENGTHC给的答案是25呀。还有trim(City_Country)长度也是25.
我的问题是为什么lengthc是25?
疯掉了!
t*****2
发帖数: 94
14
没有解决我的问题呀。我知道长度怎么来的。问题的关键是:
City_Country=substr(First,1,7)||', '||'England';
7+2+7=16
但是LENGTHC给的答案是25呀。还有trim(City_Country)长度也是25.
我的问题是为什么lengthc是25?
LENGTH 给的是16.
length : 16
lengthc: 25
lengthc(trim(.)): 25
中间肯定是没有空格,结尾也没有呀。长度怎么可能是25呢?
疯掉了!
k*z
发帖数: 4704
15
because it is in the middle cant be deleted.

【在 t*****2 的大作中提到】
: 没有解决我的问题呀。我知道长度怎么来的。问题的关键是:
: City_Country=substr(First,1,7)||', '||'England';
: 7+2+7=16
: 但是LENGTHC给的答案是25呀。还有trim(City_Country)长度也是25.
: 我的问题是为什么lengthc是25?
: LENGTH 给的是16.
: length : 16
: lengthc: 25
: lengthc(trim(.)): 25
: 中间肯定是没有空格,结尾也没有呀。长度怎么可能是25呢?

d******9
发帖数: 404
16
请仔细阅读我的回复。
In brief, 当空格在末尾的时候,length does not count the blanks, but lengthc
does!
say:
X=‘abcde###'; #= blank spaces.
Then the length of X is 8, which can be shown by viewing the column
properties, but when use length functions:
L1=length(X) = 5; --- does not count the trailing blanks.
L2=lengthc(X) =8; --- count the trailing blanks.

【在 t*****2 的大作中提到】
: 没有解决我的问题呀。我知道长度怎么来的。问题的关键是:
: City_Country=substr(First,1,7)||', '||'England';
: 7+2+7=16
: 但是LENGTHC给的答案是25呀。还有trim(City_Country)长度也是25.
: 我的问题是为什么lengthc是25?
: LENGTH 给的是16.
: length : 16
: lengthc: 25
: lengthc(trim(.)): 25
: 中间肯定是没有空格,结尾也没有呀。长度怎么可能是25呢?

1 (共1页)
进入Statistics版参与讨论
相关主题
a problem from sas base testa question about length assignment
sas base 123 question 76 疑问再问三个关于length的问题,谢谢
如何找到两个相同character在一个string中的位置?弱问:一道BASE题,怎么也不明白
如何获得最后的几个数字SAS base string question
#SAS BASE 问题,明天就考试了##百思不得其解的sas base 123题第76题
SAS BASE的一道题不明白,青椒帮忙看一道题
base 123题第72/73题求解:关于substr的返回长度还问道SAS的题目
another sas question[合集] 请教sas base 123中几题
相关话题的讨论汇总
话题: city话题: country话题: length话题: first话题: substr