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;
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;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.