BookmarkSubscribeRSS Feed
tulip
Calcite | Level 5
Hi, pros:

I have

data1: with a variable (Destination) with several values (123, 281, ...) ;
data2: structure as follows
id Des1 Des2 Des3
1 123 234 233
1 234 281 341
2 ....

Goal: if a person goes to any one of Destination by looking at 3 field of Des1, Des2, Des3, I would like to subset.

I can do it by using array and macro.

Do you think SQL can do a better job? If so, how. Please advise. Thanks.

Tulip.
2 REPLIES 2
LinusH
Tourmaline | Level 20
I don't know about better, I came to think of using IN sub-queries:

select data2.*
from data2
where data2.Des1 in(select Destination from data1)
or data2.Des2 in(select Destination from data1)
or data2.Des3 in(select Destination from data1)
;

If your destination table is not huge, it would be feasable.

/Linus
Data never sleeps
tulip
Calcite | Level 5
Hi, Linus:

Thanks a lot. It is much better than the way I used before.

Nice weekend, Tulip

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1940 views
  • 0 likes
  • 2 in conversation