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

I have a large data set that contains ID, day, and weight. I need to determine the difference between starting and ending weight for each ID. I have been working with IF statements to try to conquer this but have been unsuccessful. For example, I want to tell SAS that "if" day = 10 then take the corresponding weight - day 1 weight. I have an example of what my output from SAS currently looks like.

 

Thanks for your help.

 

 

IDday weight  
25110 
25210.6 
25310.9 
25411.3 
25512 
25612.4 
25712.3 
25813 
25913.5 
251014.14.1
5819.8 
58210.2 
58310.6 
58411.5 
58511.8 
58612.8 
58712.9 
58813.5 
58913.9 
581014.64.8
1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
data want; 
set have;
by id;
retain first_weight;
if first.id then first_weight=weight;
if last.id then diff=weight-first_weight;
run;

View solution in original post

2 REPLIES 2
ballardw
Super User

Many users here don't want to download Excel files because of virus potential, others have such things blocked by security software. Also if you give us Excel we have to create a SAS data set and due to the non-existent constraints on Excel data cells the result we end up with may not have variables of the same type (numeric or character) and even values.

 

The instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to create data step code you can post to the forum either by pasting or attaching as a TEXT file.

Reeza
Super User
data want; 
set have;
by id;
retain first_weight;
if first.id then first_weight=weight;
if last.id then diff=weight-first_weight;
run;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1357 views
  • 1 like
  • 3 in conversation