0

I have 2 lists of values in 2 variables, which contain ZIP-codes in string, as they have numbers and letters. My first list contains 33.000 ZIP-codes, the second list 1400. Now I want to check if my ZIP-codes from the second variable are also in the first variable, and if so, give a third variable the code 1. If it is not in both variable lists, give it the code 0. I've tried to compare datasets, but that only compares if the variable is on the same position. Writing a loop didn't work so far. Hopefully anyone can help! Thanks in advance.

eli-k
  • 10,898
  • 11
  • 40
  • 44
  • I wrote an answer based on assumptions about how your data looks like. Please note, when you write questions in StackOverflow, you should add a detailed description of how you data is structured, some data sample/example with the expected results - this will make it easier to understand what the problem is and to suggest solutions. – eli-k Apr 01 '20 at 10:35

1 Answers1

1

Assuming you have two datasets:

dataset activate list2.
compute InBothLists=1.
sort cases by zipcode.

dataset activate list1.
sort cases by zipcode.
match files /file=* /table=list2 /by zipcode.
execute.

In the code above use your own dataset names and variable names - make sure your have the same variable name for the zipcode in both lists.
Once you run this you will have a new variable in the dataset list1 which has the value 1 for zipcodes that also appear in list2.

eli-k
  • 10,898
  • 11
  • 40
  • 44