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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.