BookmarkSubscribeRSS Feed
Emilygreene0305
Calcite | Level 5

Need help to create a by variable to merge two datasets. 

One dataset is parent survey and one is a child. However they have no similar variable to link them but they are matched. I.e. participant ID for adults are even and children are odd.

For example, parent 1000 matches with child 1001, parent 1002 matches with child 1003

3 REPLIES 3
Tom
Super User Tom
Super User

Make a new variable in the CHILD dataset that is one less than the child ID value and then merge on that.  Or do both in one step using PROC SQL.

data parent;
  input parentid name :$20.;
cards;
1000 Smith
;

data child;
  input childid age ;
cards;
1001 10
;

proc sql;
create table want as select * 
from parent full join child
on parent.parentid = child.childid -1 
;
quit;
Ksharp
Super User
Are they exactly one-to-one matched ?
One parent might match multiple child ?
And could you post some data and desired output to explain your problem ?

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 489 views
  • 0 likes
  • 4 in conversation