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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.