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;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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