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

Hii I have following input  

Input dataset :

    id      max   score

   101     20        45  

   101     32        65    

   101     28        50   

output :

    id      max   score  change

   101     20        45          5

   101     28        50         15

   101     32        65          .

 

pls  help me  out

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

Perhaps:

 

proc sort data=have;

   by id score;

run;

 

data want;

set have;

by id;

if last.id=0 then do;

   _n_ = _n_ + 1;

   set have (keep=score rename=(score=next_score)) point=_n_;

   change = next_score - score;

end;

drop next_score;

run;

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

I don't understand how the column named change is computed. You didn't explain that.

--
Paige Miller
Astounding
PROC Star

Perhaps:

 

proc sort data=have;

   by id score;

run;

 

data want;

set have;

by id;

if last.id=0 then do;

   _n_ = _n_ + 1;

   set have (keep=score rename=(score=next_score)) point=_n_;

   change = next_score - score;

end;

drop next_score;

run;

molla
Fluorite | Level 6

Is there any way to get the observations of one varaible to other by excluding the first value of that varaible ie

 

score  score2

45        50

50        64

65

 

Ksharp
Super User
data have;
input id      max   score;
cards;
   101     20        45  
   101     32        65    
   101     28        50
;
run;
proc sort data=have;by id score;run;
data want;
 merge have have(keep=id score rename=(id=_id score=_score) firstobs=2);
 if id=_id then diff=_score-score;
 drop _:;
run;

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

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
  • 4 replies
  • 815 views
  • 0 likes
  • 4 in conversation