Dear all,
if I have a data that looks like this
data have;
input id 2. subjid $6. var1 $2. var2 $2. ;
datalines;
1 pat_1 A B
14 pat_2 C D
14 pat_3 E F
14 pat_4 G H
2 pat_5 I J
;
run;
and want the subjid to be the same where id is the same, how do I do that?
The data seems to be not sorted by id, but is grouped by id? If the data is grouped try:
data want;
set have(rename= (subjid = _subjid));
by id notsorted;
length subjid $ 6;
retain subjid;
if first.id then subjid = _subjid;
drop _subjid;
run;
So for ID = 14, what subjid should be applied ?
The first one encountered?
The data seems to be not sorted by id, but is grouped by id? If the data is grouped try:
data want;
set have(rename= (subjid = _subjid));
by id notsorted;
length subjid $ 6;
retain subjid;
if first.id then subjid = _subjid;
drop _subjid;
run;
Just for fun.
data have; input id 2. subjid $6. var1 $2. var2 $2. ; datalines; 1 pat_1 A B 14 pat_2 C D 14 pat_3 E F 14 pat_4 G H 2 pat_5 I J ; run; proc sql; create table want as select id,min(subjid) as subjid,var1,var2 from have group by id; quit;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.