i have a dataset like this.
I want to use the first value of weight for the respective subjects.someone pls help me.
input desired output
id weight id weight
1 58 1 58
1 . 1 58
1 . 1 58
2 62 2 62
2 . 2 62
2 . 2 62
3 57 3 57
3 . 3 57
3 . 3 57
it works. thank u so much
Hi Akhila,
i hope below code will help...
data have;
input id weight;
cards;
1 58
1 .
1 .
2 62
2 .
2 .
3 57
3 .
3 .
;
run;
proc sort ; by id;
run;
data want;
set have;
by id;
retain i ;
if first.id then i=weight;
weight=i;
drop i;
run;
Thanks...
it works. thank u so much
@AKHILA, please mark @singhsahabs answer as the solution to your problem.
data have;
input id weight;
cards;
1 58
1 .
1 .
2 62
2 .
2 .
3 57
3 .
3 .
;
run;
data want;
update have (obs=0) have;
by id;
output;
run;
data have;
input id weight;
cards;
1 58
1 .
1 .
2 62
2 .
2 .
3 57
3 .
3 .
;
run;
proc sql;
create table want(drop=w) as
select *,max(w) as weight
from have(rename=weight=w)
group by id;
quit;
data have;
input id weight;
cards;
1 58
1 .
1 .
2 62
2 .
2 .
3 57
3 .
3 .
;
run;
data want;
merge have(drop=weight) have(where=(weight > .));
by id;
run;
data have;
input id weight;
cards;
1 58
1 .
1 .
2 62
2 .
2 .
3 57
3 .
3 .
;
run;
data want;
if _n_=1 then do;
dcl hash H (dataset:'have(where=(weight > .))') ;
h.definekey ("id") ;
h.definedata ("weight") ;
h.definedone () ;
end;
set have;
_iorc_=h.find();
run;
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!
Get started using SAS Studio to write, run and debug your SAS programs.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.