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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: