BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
bharath86
Obsidian | Level 7

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

 

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

2 REPLIES 2
Ksharp
Super User
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;
Astounding
PROC Star

A one-step approach:

data want;
   retain recno 1;
   drop recno;
   set b;
   output;
   set a point=recno;
   output;
run;

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

How to choose a machine learning algorithm

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.

Discussion stats
  • 2 replies
  • 1309 views
  • 2 likes
  • 3 in conversation