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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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