I have 3 data sets (state, district, school). The State and District data sets listed below are the entire set but the school data set has 189 obs. After each obs in the school data set, I want to include the corresponding district and state observation based on the testgrade.
DATA I WANT:
recordtype | schoolid | Teacher | testgrade | elalev1pct1 | elalev1pct2 | elalev1pct3 |
3School | 12 | SMITH | 3 | 100 | 0 | 0 |
2District | 3701999 | 3 | 40.8 | 29 | 30.2 | |
1State | 9999999 | 3 | 40 | 28.6 | 31.4 | |
3School | 12 | JONES | 5 | 40 | 13.3 | 46.7 |
2District | 3701999 | 5 | 44.5 | 30.8 | 24.6 | |
1State | 9999999 | 5 | 44.7 | 29.1 | 26.1 |
THE 3 DATA SETS I HAVE:
DATA SET = STATE | ||||||
recordtype | schoolid | teacher | testgrade | elalev1pct1 | elalev1pct2 | elalev1pct3 |
1State | 9999999 | 3 | 40 | 28.6 | 31.4 | |
1State | 9999999 | 4 | 45.4 | 31.3 | 23.3 | |
1State | 9999999 | 5 | 44.7 | 29.1 | 26.1 | |
1State | 9999999 | 6 | 49.9 | 23.5 | 26.6 | |
1State | 9999999 | 7 | 46.4 | 24.4 | 29.2 | |
1State | 9999999 | 8 | 46.2 | 26.9 | 26.9 | |
DATA SET = DISTRICT | ||||||
recordtype | schoolid | teacher | testgrade | elalev1pct1 | elalev1pct2 | elalev1pct3 |
2District | 3701999 | 3 | 40.8 | 29 | 30.2 | |
2District | 3701999 | 4 | 44.4 | 34 | 21.6 | |
2District | 3701999 | 5 | 44.5 | 30.8 | 24.6 | |
2District | 3701999 | 6 | 47.8 | 23.5 | 28.7 | |
2District | 3701999 | 7 | 46.3 | 26.3 | 27.5 | |
2District | 3701999 | 8 | 48.7 | 26.4 | 24.9 | |
DATA SET = SCHOOL | ||||||
recordtype | schoolid | Teacher | testgrade | elalev1pct1 | elalev1pct2 | elalev1pct3 |
3School | 12 | SMITH | 3 | 100 | 0 | 0 |
3School | 12 | JONES | 5 | 40 | 13.3 | 46.7 |
3School | 12 | MOORE | 4 | 8.3 | 25 | 66.7 |
3School | 12 | ABLE | 7 | 27.8 | 27.8 | 44.4 |
3School | 12 | BAKER | 8 | 31.6 | 36.8 | 31.6 |
3School | 13 | DELTA | 6 | 30.7 | 34.2 | 35.1 |
3School | 13 | ECHO | 4 | 0 | 8.3 | 91.7 |
3School | 13 | FOXTROT | 3 | 9.5 | 52.4 | 38.1 |
3School | 13 | GAMMA | 5 | 58.8 | 29.4 | 11.8 |
Data combined;
set SCHOOL; output;
set DISTRICT; output;
Set STATE; output;
run;
Data combined;
Set STATE DISTRICT SCHOOL;
by testgrade descending recordtype;
run;
Data combined;
Set STATE;
set DISTRICT;
set SCHOOL;
run;
Data combined;
set SCHOOL; output;
set DISTRICT; output;
Set STATE; output;
run;
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.
Ready to level-up your skills? Choose your own adventure.