我有一个有1美元符号($)的观察,和有2个美元符号($)的观察。我想为每种类型的观察值分配不同的值。它应该看起来像这样:
"$200 $300“被赋值1。"$200”被赋值2。
我尝试了一整天的Perl通配符,但是没有成功。
谢谢。
发布于 2012-04-06 01:56:58
使用SAS countc()函数来计算'$‘出现的次数如何?
%put %sysfunc(countc($300 $400,'$')); /* returns 2 */
%put %sysfunc(countc($300 ,'$')); /* returns 1 */发布于 2012-04-06 01:22:49
您可以使用goatse operator
my @str = ( '$200 $300', '$200' );
foreach my $str ( @str ) {
my $count =()= $str =~ /\$/g;
print "count for $str is $count\n";
}然后根据您的$count,相应地赋值。
https://stackoverflow.com/questions/10032985
复制相似问题