Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with "SET KEY=" please

Status
Not open for further replies.

barryp

Programmer
Jan 30, 2002
48
GB
Hi
I have an index (not unique) on a dataset.
Why does

SET dataset KEY=mykey;
SET dataset KEY=mykey;
SET dataset KEY=mykey;
SET dataset KEY=mykey;

give different results to

i=4;
DO WHILE(i>0);
SET dataset KEY=mykey;
i=i-1;
END;

The first gives the first occurrence of a record matching the key FOUR times whereas the second code extract gives the first 4 records that match the key.

This may seem a trivial example but I'm trying to pin down a more complex case.

I am given a list of names. I have to find all records in my dataset containing the names. I the same name happens to occur twice AND THSE TWO OCCURRENCES ARE ADJACENT then the second lookup fails. (the good old /unique problem)

Can anyone explain what is happening with the above code extracts ?

Barry
 
Why can't you use the IN function in a WHERE or IF statement?
Ex.
if your_var in ("name1","name2","name3",....);

You may want to use the trim and/or upcase functions too.
Klaz
 
...or put the list of names into a dataset and do a merge.

Using multiple Set statements, especially multiple SET statements with the same dataset will do a specific and unusual function. You need to fully read up on what the SET statement does when used multiple times. From what I can remember, what you are doing above tells the datastep to read the same table 4 times, which sounds like a really inefficient way of doing what you want.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top