BookmarkSubscribeRSS Feed
manya92
Fluorite | Level 6

Hi all. My dataset looks like the one below. I need to make a new variable called modification based on the variable amount. if the difference between the subsequent amounts for the same patientID is at least 15 then the dose is modified else not. How to achieve this in SAS?

Obs PatientID sub_dates amount1234567891011121314151617181920

F012DC0F325EF12/31/2014250
F012DC0F325EF01/14/2015337
F012DC0F325EF01/28/2015337
F012DC0F325EF02/16/2015337
F012DC0F325EF03/02/2015337
F012DC0F325EF03/26/2015337
F012DC0F325EF04/13/2015337
F012DC0F325EF04/27/2015337
F012DC0F325EF05/13/2015337
F012DC0F325EF05/28/2015337
F012DC0F325EF06/10/2015337
F03254A1ADC2601/11/2017350
F03254A1ADC2601/30/2017350
F03254A1ADC2602/13/2017350
F03254A1ADC2603/01/2017350
F03254A1ADC2603/22/2017350
F03254A1ADC2604/04/2017350
F03254A1ADC2604/18/2017350
F0577A8783BD906/25/2014330
F0577A8783BD907/09/2014330
2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

A few questions.. Do you have SAS/ETS? Also, is 'difference' both positive and negative? Should the dose be modified if the subsequent value is both 16 higher/lower than the current observation?

ballardw
Super User

As a hint for asking questions in the future:

1) provide just enough data to illustrate the issue/ logic/ question. The last 6 or 7 observations for patient F012DC0F325EF are not actually adding any information to the use case

2) Show what your expected output given the input example would be. For instance you do want a new variable with the difference of the amount? Or a flag that indicates "modify" when out of range.

3) As @PeterClemmensen asked, be sure to clearly indicate clearly which values meet your objective. It would be best if your input data showed both declines and increases past the threshold so that the example output would clarify whether not a specific observation meets the rule.

4) Ideally your example data should be in the form of data step code that allows us to test code against values. And you should provide the data step because if we make one with similar data we might make a choice that does not work for your data. For instance I would make sure that your date value is a SAS date value. But we have lots of questions about dates on this forum where it turns out the actual variable for a date is character. So solutions using actual date values "do no work" for a posters question because they did not describe their data accurately. A data step with the same variable names, types, lengths and formats means that we are on the same page for the data.

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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
  • 1196 views
  • 0 likes
  • 3 in conversation