# Thread: In SAS - Compare two strings, arrays, etc

1. ## In SAS - Compare two strings, arrays, etc

I am attaching a sample of what I'm working with. Please help me with the SAS code for this.

Here's what I want to do -

I want to know if any of the values, per famid, appearing in columns dx1-dx4 are missing in columns d1-d5. If so, then which ones.

For example, for famid 2, values for dx1 and dx2 are found in columns d1 and d3 (order doesn't matter). there's another code listed under d2 but that's ok since im only interested in checking one way.
Next famid, 3, only 5678 appears in d1-d4 so i need a code that spits out the remaining 3 (3456 ,f3456,d4567).

Here's what I have tried so far but I am not having any luck -

1)
dxx=catx(',', of dx1-dx4);
dxd=catx(',', of d1-d5);
if dxx='' then ct=0;
else ct=count(dxx,',')+1;
do i=1 to ct;
if scan(dxx,i,',') notin (dxd) then eq='N';
end;

I get errors here and this doesn't tell me which codes arent present in the other but it's a start :-)

2)
diag=catx(',', of d1-d5);
diag1=catx(',', of dx1-dx4);

if diag1='' then diag_ct1=1;
else diag_ct1=count(diag1,',')+1;

do j=1 to diag_ct1;
x= index(diag,scan(diag1,j,','));
end;

if x=0 then do;

Not sure where to go from here.

2. ## Re: In SAS - Compare two strings, arrays, etc

I want to know if any of the values, per famid, appearing in columns dx1-dx4 are missing in columns d1-d5. If so, then which ones.
I think the easy way is using PROC TRANSPOSE.
Split two dataset based on dx and d ( or you can split first and then transpose)

Then Merge the two data set.
SET1: contains dx1-dx4 variables in COL1 (in=set1)
SET1: contains d1-d5 variables in COL1 (in= set2)

merge by id and COL1. then put condition
Code:
``if set1 and not set2;``
*Right now i don't have SAS with me.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts