BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9

data pacemaker1617;
set cihi.dad1617;
ARRAY ARRAY_IC [20] INTERV_CODE_01- INTERV_CODE_20;
if PROVINCE_ISSUING_HCN='ON' and RESPONSIBILITY_FOR_PAYMENT='01' and HCN_INDEX='H'
and AGE >=18 ;
DO I=1 TO 20;

IF ARRAY_IC[I] in ('1YY55LANM') THEN output;

END;
RUN;

 

I have 25 more codes for which I need to create data extracts similar to the way done above

What would be an easy way to modify the code above to do the same

4 REPLIES 4
Ranjeeta
Pyrite | Level 9

The intent is to count a record if the code occurs in any one of the 20 fields which is what the code is doing 

But I want to understand if there is an easier way to create an extract for 25 different codes

novinosrin
Tourmaline | Level 20

@Ranjeeta  I think you are prolly after this

 

data pacemaker1617;
set cihi.dad1617;
ARRAY ARRAY_IC [20] INTERV_CODE_01- INTERV_CODE_20;
if PROVINCE_ISSUING_HCN='ON' and RESPONSIBILITY_FOR_PAYMENT='01' and HCN_INDEX='H'
and AGE >=18 ;
if  '1YY55LANM' in ARRAY_IC then output;
RUN;

ballardw
Super User

Example starting data and what the result should look like are helpful.

 

If you mean that you have 25 other values that occur in the array ARRAY_IC I would likely put them into a temporary array and use the WHICHC function to search the temporary array for each value in the array.

 

data pacemaker1617;
   set cihi.dad1617;
   ARRAY ARRAY_IC [20] INTERV_CODE_01- INTERV_CODE_20;
   array t [4] $ 10 _temporary_ ( '1YY55LANM' '1ZZ55LANZ' '1XX55LANX' '1QQ55LANQ');
   if PROVINCE_ISSUING_HCN='ON' and RESPONSIBILITY_FOR_PAYMENT='01' and HCN_INDEX='H'
   and AGE >=18 ;
   DO I=1 TO 20;
   IF whichc(ARRAY_IC[I], of t(*) )>0 THEN output;

   END;
RUN;

I picked 10 as the length of the elements to allow the string value of the code to be a little longer than the displayed one. If your lengths vary more than make sure the length in the array definition is large enough.

 

This presumes that if a value of the code in ARRAY_IC is duplicated it should create duplicate outputs.

 

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 4 replies
  • 756 views
  • 0 likes
  • 4 in conversation