- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I merged a data set with another data set by subject. The one data set includes the variables arm, and armn, but the other one just includes subjects. I would like to have it so that the newly merged data set contains the same values for arm and armn after the merge for each subject.
edit: in case there is confusion, the data set that is presented below is the merged data set. I'm trying to get repeat values of arm and armn for each subject so that the final data set looks like:
001, a, 1
001, a, 1
002, b, 2
002, b, 2
002, b, 2
003, c, 3
003, c, 3
003, c, 3
Thanks!
data have1;
infile datalines dsd dlm=",";
input subject $ arm $ armn;
datalines;
001, a, 1
001, , ,
002, b, 2
002, b, 2
002, ,
003, c, 3
003, ,
003, ,
;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Hello_there wrote:
Hi Quentin, the data set that is presented is the new data set after the merge. I would like to know how I can repeat the values for arm and armn for each subject bc after the merged happened, the data set that did not include those variables were displayed as missing.
Then most likely you made the mistake of have the variables on BOTH of the input datasets. The variables you want replicated should only appear on the dataset that has just the one observation per BY group.
So you have your subject level dataset with ARM and
data subjects;
input subject $ arm $ armn;
datalines;
001 a 1
002 b 2
003 c 3
;
And your dataset that has repeated measure per subject. So perhaps heart rate measure at different visits.
data visits;
input subject $ visit hr ;
datalines;
001 1 65
001 2 70
002 1 80
002 2 75
003 1 72
;
Then you can merge by SUBJECT and the values of ARM and ARMN will be retained onto every observation (that is in the SUBJECTS dataset).
data want;
merge subjects visits;
by subject;
run;
Results
Obs subject arm armn visit hr 1 001 a 1 1 65 2 001 a 1 2 70 3 002 b 2 1 80 4 002 b 2 2 75 5 003 c 3 1 72
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
I'm confused. You're asking about merging, but you only show one dataset. Suggest you show a small example of both datasets you are merging, and the code you used to merge them. Then you can also show the output you get from merging them, and describe why you are unhappy with that output.
Next webinar will be in January 2025. Until then, check out our archives: https://www.basug.org/videos. And be sure to subscribe to our our email list.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@Hello_there wrote:
Hi Quentin, the data set that is presented is the new data set after the merge. I would like to know how I can repeat the values for arm and armn for each subject bc after the merged happened, the data set that did not include those variables were displayed as missing.
Then most likely you made the mistake of have the variables on BOTH of the input datasets. The variables you want replicated should only appear on the dataset that has just the one observation per BY group.
So you have your subject level dataset with ARM and
data subjects;
input subject $ arm $ armn;
datalines;
001 a 1
002 b 2
003 c 3
;
And your dataset that has repeated measure per subject. So perhaps heart rate measure at different visits.
data visits;
input subject $ visit hr ;
datalines;
001 1 65
001 2 70
002 1 80
002 2 75
003 1 72
;
Then you can merge by SUBJECT and the values of ARM and ARMN will be retained onto every observation (that is in the SUBJECTS dataset).
data want;
merge subjects visits;
by subject;
run;
Results
Obs subject arm armn visit hr 1 001 a 1 1 65 2 001 a 1 2 70 3 002 b 2 1 80 4 002 b 2 2 75 5 003 c 3 1 72
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content