BookmarkSubscribeRSS Feed
mwei0041
Calcite | Level 5

 

I want a variable "T08_count" that counts the 6 character long variables "code_1-code_44", which BEGIN with "T08". I have made following code, but then it count all variables of "code_1-code_44" which contain "T08" at any place in the string: 

 

data pb; 

set work.pb;

array t (1) $6_temporary_('T08');

do i=1 to dim(t);

T08_count=sum(T08_count, count(catx(' ', of code_1-code_44), STRIP( t[i], 'i'));

end;

drop i;

run; 

 

1 REPLY 1
PaigeMiller
Diamond | Level 26

This is UNTESTED code. If you want tested code, you must provide a portion of your data as SAS data step code which you can type in yourself or have SAS create it (instructions); and not in any other format. This code uses the =: (note the colon after the equal sign) to test if a string begins with a certain value.

 

data want;
    set have;
    array y code_1-code_44;
    do i=1 to dim(y);
        count=sum(count,y(i)=:'T08');
    end;
run;
        

 

--
Paige Miller
How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 532 views
  • 3 likes
  • 2 in conversation