BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
kingsii24
Fluorite | Level 6

I have a dataset that contains procedure codes ranging from 1 to 12 (cpt_code1-cpt_code12), that were performed on the same day. I need to search across these variables for specific codes that are related to a specific test being carried on on a patient.

The codes related to each procedure are listed below:

 

Test1: 81507, 84702

Test2: 84163, 84702, 76813

Test3: 82677, 84702, 86336
Test4: 82105, 84702, 86336, 82677


Note that  all the codes listed for each test need to exist in the same row (i.e.cpt_code1-cpt_code12) for that test to be valid. In other words, let's say for a specific person, their row only contains cpt code 81507, I wouldn't be able to classify them as receiving Test1 since cpt code 84702 is not included in that line.

 

I've tried searching previous forums (and reading about arrays) but I can't seem to find anything that matches my situation. 

 

Below is a snippet of what I have so far:

data work.example2;
length test_type $20.;
set work.example;
array acpt_code(1:12) cpt_code1-cpt_code12;
do i=1 to 12;
if acpt_code[i] in ('81507', '84702') then test_type="Test1";
end;
run;

I know the above code is not correct since I'm just telling SAS to search across the variables to see if at least one of the cpt codes exist, and I need to know that both codes exist in order for Test1 to be assigned as the test type (which is where I'm stuck).

 

Thanks in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @kingsii24,

 

Just adapt the program code to the logic and search for those specific codes in the array (and not vice versa), for example:

if '81507' in acpt_code & '84702' in acpt_code then test_type="Test1";

 

View solution in original post

2 REPLIES 2
data_null__
Jade | Level 19

Show example input your HAVE data.

FreelanceReinh
Jade | Level 19

Hi @kingsii24,

 

Just adapt the program code to the logic and search for those specific codes in the array (and not vice versa), for example:

if '81507' in acpt_code & '84702' in acpt_code then test_type="Test1";

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 721 views
  • 0 likes
  • 3 in conversation