Hi,
I want to append one record from dataset A to all records in dataset B.
Dataset A doesnt have an id column but this should be appended to all records in B dataset.
There may be multiple records in dataset B for each ID.
Dataset-A
| bb | cc |
| Test record |
Test record |
Dataset-B
| id | bb | cc |
| 1 | fadfafa | adafa |
| 2 | adfa | adafa |
| 3 | rtwt | kghj |
| 4 | ghjkgdgh | luy |
| 5 | fgs | gsyhs |
Output dataset should look like this.
| id | bb | cc |
| 1 | fadfafa | adafa |
| 1 | Test record | Test record |
| 2 | adfa | adafa |
| 2 | Test record | Test record |
| 3 | rtwt | kghj |
| 3 | Test record | Test record |
| 4 | ghjkgdgh | luy |
| 4 | Test record | Test record |
| 5 | fgs | gsyhs |
| 5 | Test record | Test record |
data A;
input bb $ cc $;
cards;
test test
;
run;
data B;
infile cards expandtabs truncover;
input id bb $ cc $;
cards;
1 fadfafa adafa
2 adfa adafa
3 rtwt kghj
4 ghjkgdgh luy
5 fgs gsyhs
;
run;
data temp;
set B(keep=id);
if _n_=1 then set A;
run;
data want;
set B temp;
by id;
run;
data A;
input bb $ cc $;
cards;
test test
;
run;
data B;
infile cards expandtabs truncover;
input id bb $ cc $;
cards;
1 fadfafa adafa
2 adfa adafa
3 rtwt kghj
4 ghjkgdgh luy
5 fgs gsyhs
;
run;
data temp;
set B(keep=id);
if _n_=1 then set A;
run;
data want;
set B temp;
by id;
run;
A one-step approach:
data want;
retain recno 1;
drop recno;
set b;
output;
set a point=recno;
output;
run;
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!
Use this tutorial as a handy guide to weigh the pros and cons of these commonly used machine learning algorithms.
Find more tutorials on the SAS Users YouTube channel.