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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.