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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!
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.