BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
AKHILA
Obsidian | Level 7

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

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
AKHILA
Obsidian | Level 7

it works. thank u so much

View solution in original post

7 REPLIES 7
singhsahab
Lapis Lazuli | Level 10

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...

AKHILA
Obsidian | Level 7

it works. thank u so much

PeterClemmensen
Tourmaline | Level 20

@AKHILA, please mark @singhsahabs answer as the solution to your problem.

novinosrin
Tourmaline | Level 20
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;
novinosrin
Tourmaline | Level 20

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;
novinosrin
Tourmaline | Level 20
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;
novinosrin
Tourmaline | Level 20

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;

Catch up on SAS Innovate 2026

Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.

Explore Now →
Develop Code with SAS Studio

Get started using SAS Studio to write, run and debug your SAS programs.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 5333 views
  • 1 like
  • 4 in conversation