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;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.