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;

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
  • 2 replies
  • 859 views
  • 1 like
  • 3 in conversation