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-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 571 views
  • 2 likes
  • 3 in conversation