楼主: Cecilia_Xi
1301 1

[问答] 【CountW函数】系列2:delimiter n 和d [推广有奖]

  • 1关注
  • 1粉丝

已卖:3份资源

硕士生

89%

还不是VIP/贵宾

-

威望
0
论坛币
806 个
通用积分
8.0110
学术水平
10 点
热心指数
9 点
信用等级
6 点
经验
3205 点
帖子
99
精华
0
在线时间
289 小时
注册时间
2019-1-30
最后登录
2022-4-20

楼主
Cecilia_Xi 在职认证  发表于 2020-3-23 13:24:27 |AI写论文
10论坛币
求问为什么结果不是:  obs    n    d
  1      3    4
  2      1    5
  1. data test;
  2.         input string $char60.;
  3.         datalines;
  4. '_'2+2=4
  5. \\"Windows"  "\Path\Names\Use\Backslashes
  6. ;
  7. run;
  8. data test1;
  9.     set test;
  10.         d=countw(string,,'d');
  11.         n=countw(string,,'n');
  12. run;
  13. proc print data=test1;run;
复制代码
微信图片_20200323102701.png 微信图片_20200323102709.png

沙发
Cecilia_Xi 在职认证  发表于 2020-3-24 09:20:53
Remember that character variables are padded with trailing blanks. When you specify the delimiters and do not include a blank as a delimiter, the trailing blanks counts as a word.  You can use the TRIMN function to remove trailing blanks.
string='_'2+2=4 d=3 n=4
string=\\"Windows"  "\Path\Names\Use\Backslashes d=1 n=5

  1. data test1;
  2. set test;
  3. d=countw(trimn(string),,'d');
  4. n=countw(trimn(string),,'n');

  5. put (string d n)(=) ;
  6. run;
复制代码


您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-29 11:26