Loop through second Dataset

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

Loop through second Dataset

Hi All,

 

       I have two sasdatasets , one has column ID which has 8 digit number. The second dataset has a text field in which it has ID from the first dataset any where placed in the text field.  I need a column in the second dataset which says "exists"  if the ID exists in the first dataset.

 

Example :

  First Dataset : 12345678

  Second data set text Value: **Request #12345678-Corporate Membership

 

In the text field the ID value can be anywhere in the text. Basically for every ID in the first dataset it has to loop through all records in the second  dataset and put a flag exists in that row where it matches in the second dataset.

 

Thanks In Advance,

Vani.


Accepted Solutions
Solution
‎09-14-2016 12:52 PM
Esteemed Advisor
Esteemed Advisor
Posts: 7,253

Re: Loop through second Dataset

index() function should be able to handle it:

proc sql;
  create table WANT as
  select  A.*,
             case when B.VAL is not null then 1 else 0 end
  from    LONGSTRING A
  left join SMALLDATA B
  on        index(A.VAL,B.VAL)>0;
quit;

This should join the small dataset to the larger one, based on finding the small string in the big string.

View solution in original post


All Replies
Solution
‎09-14-2016 12:52 PM
Esteemed Advisor
Esteemed Advisor
Posts: 7,253

Re: Loop through second Dataset

index() function should be able to handle it:

proc sql;
  create table WANT as
  select  A.*,
             case when B.VAL is not null then 1 else 0 end
  from    LONGSTRING A
  left join SMALLDATA B
  on        index(A.VAL,B.VAL)>0;
quit;

This should join the small dataset to the larger one, based on finding the small string in the big string.

New Contributor
Posts: 2

Re: Loop through second Dataset

Thank you. It did work , got that extra flag column as I want. 

Grand Advisor
Posts: 10,251

Re: Loop through second Dataset

Please provide some example data from each data set and the result. The wording you are describing for output has a couple of different interpretations and an example of what the output looks like would help determine which meaning(s) to use. For instance what if the ID is duplicated in the first set. One interpretation would be to create two or more 'marked' result records in the output.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 309 views
  • 0 likes
  • 3 in conversation