I have observations that have 1 dollar signs ($), and observations that have 2 dollar signs ($). I want to assign different values to each type of observation. It should look something like this:
"$200 $300" gets assigned 1. "$200" gets assigned 2.
I've tried playing with Perl wildcards all day but no luck.
Thanks.
How about the SAS countc()
function to count the number of times '$' appears?
%put %sysfunc(countc($300 $400,'$')); /* returns 2 */
%put %sysfunc(countc($300 ,'$')); /* returns 1 */
You could use the goatse operator:
my @str = ( '$200 $300', '$200' );
foreach my $str ( @str ) {
my $count =()= $str =~ /\$/g;
print "count for $str is $count\n";
}
Then depending on what your $count
is, assign the values accordingly.