+ Reply to Thread
Results 1 to 2 of 2

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

  1. #1
    Points: 3,051, Level: 34
    Level completed: 1%, Points required for next Level: 149

    Location
    IL
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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.
    Attached Files

  2. #2
    Bhoot
    Points: 1,434, Level: 21
    Level completed: 34%, Points required for next Level: 66

    Posts
    1,759
    Thanks
    40
    Thanked 128 Times in 107 Posts

    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.
    In the long run, we're all dead.

+ Reply to Thread

Similar Threads

  1. Replies: 3
    Last Post: 02-13-2011, 07:54 AM
  2. strings
    By WeeG in forum R
    Replies: 2
    Last Post: 12-08-2010, 12:53 AM
  3. Replies: 3
    Last Post: 08-04-2010, 05:09 PM
  4. Help in arrays
    By tanz in forum SAS
    Replies: 0
    Last Post: 08-10-2009, 12:11 PM
  5. Data strings
    By makky_j_g in forum SAS
    Replies: 1
    Last Post: 02-20-2009, 12:52 PM

Posting Permissions

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








Advertise on Talk Stats