Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loop through each observation of a string variable located in another dataset

    Hi all, I need to loop through each observation of a (string) variable of another dataset. What is the best way of doing this?

    I am trying to do:

    foreach x in var_ext {
    replace var1 = strpos(var2,x)
    }

    where var_ext is a variable in another dataset while var1 and var2 are variables in the dataset that is open.

  • #2
    I think you need to give us a clearer sense of what you want to do. As written, your example does not require any loop at all: it just requires finding the last value of var_ext, and then setting var1 to the position in var2 of that value. No other value of var_ext would matter, because each time you go through the loop, your previous work gets eliminated. I'm pretty sure that isn't what you really want to do.

    Perhaps you could give us a sample of the var2 data and the var_ext data, and then show us what you want the resulting var1 to look like. Please post your samples in code blocks (see FAQ for how to set up a code block) so that they will be both easy to read by eye and easy to work with.

    Comment


    • #3
      Hi Clyde, sorry for not being more clear, I figured out my issue, thanks for the input though.

      Comment

      Working...
      X