I have 2 datasets one has ID values and i want to merge it with text to get the values from text, i need something like below - want dataset. any help on it
| ID |
| 1 |
| 2 |
| 3 |
| 4 |
| TEXT |
| Height |
| Weight |
I want something like this
| ID | TXT |
| 1 | Height |
| 1 | Weight |
| 2 | Height |
| 2 | Weight |
| 3 | Height |
| 3 | Weight |
| 4 | Height |
| 4 |
Weight
|
With a data step.
data have1;
input ID;
datalines;
1
2
3
4
;
data have2;
input TEXT $;
datalines;
Height
Weight
;
data want;
set have1;
do i=1 to n;
set have2 point=i nobs=n;
output;
end;
run;
Result:
ID TEXT 1 Height 1 Weight 2 Height 2 Weight 3 Height 3 Weight 4 Height 4 Weight
With Proc SQL you can create cartesian product just (You haven't defined dataset names , so I'm using column names)
Proc Sql;
create table want as
select *
from ID, TEXT;
quit;
With a data step.
data have1;
input ID;
datalines;
1
2
3
4
;
data have2;
input TEXT $;
datalines;
Height
Weight
;
data want;
set have1;
do i=1 to n;
set have2 point=i nobs=n;
output;
end;
run;
Result:
ID TEXT 1 Height 1 Weight 2 Height 2 Weight 3 Height 3 Weight 4 Height 4 Weight
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
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.