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
F012DC0F325EF | 12/31/2014 | 250 |
F012DC0F325EF | 01/14/2015 | 337 |
F012DC0F325EF | 01/28/2015 | 337 |
F012DC0F325EF | 02/16/2015 | 337 |
F012DC0F325EF | 03/02/2015 | 337 |
F012DC0F325EF | 03/26/2015 | 337 |
F012DC0F325EF | 04/13/2015 | 337 |
F012DC0F325EF | 04/27/2015 | 337 |
F012DC0F325EF | 05/13/2015 | 337 |
F012DC0F325EF | 05/28/2015 | 337 |
F012DC0F325EF | 06/10/2015 | 337 |
F03254A1ADC26 | 01/11/2017 | 350 |
F03254A1ADC26 | 01/30/2017 | 350 |
F03254A1ADC26 | 02/13/2017 | 350 |
F03254A1ADC26 | 03/01/2017 | 350 |
F03254A1ADC26 | 03/22/2017 | 350 |
F03254A1ADC26 | 04/04/2017 | 350 |
F03254A1ADC26 | 04/18/2017 | 350 |
F0577A8783BD9 | 06/25/2014 | 330 |
F0577A8783BD9 | 07/09/2014 | 330 |
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?
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.
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!
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.
Ready to level-up your skills? Choose your own adventure.