BookmarkSubscribeRSS Feed
Yulka
Calcite | Level 5
There are 5 tables:
1. Year05d: 5 variables + 2 keys: zip naics
2. Year06d: 5 variables + 2 keys: zip naics
3. Year05t: 3 variables + key: zip
4. Year06t 3 variables + key: zip
5. look-up table: 2 variables: naics sic

I need one table that is unique at zip+naics level and contains all observations and all the variables from all 5 tables.
With data step the logic was as following:
1. merge Year05d Year06d by zip naics
2. merge Year05t Year06t by zip
3. merge step1 and step2
4. merge step3 and look-up table by naics

how do i do that with sql in one step?
1 REPLY 1
1162
Calcite | Level 5
I would start with something like this. Keep in mind that there's only one way to get all the observations and also be unique at the zip+naics level and that is if your first two tables only have one observation per zip+naics level and your second two tables only have one observatikon per zip level.

[pre]
proc sql;
create table all as
select *
from year05d a, year06d b, year05t c, year06t d, look-up table e
where a.zip = b.zip
and a.naics = b.naics
and c.zip = d.zip
and c.zip = a.zip
and a.naics = e.naics;
quit;
[/pre] Message was edited by: 1162

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 1 reply
  • 1095 views
  • 0 likes
  • 2 in conversation