Hi
I want to check variable for previous rows and asking how to do that. I should check if the previous rows are the same or the information is a new information for the same ID?
There is the LAG function from which you can check specific variables to see what their values are in previous rows. There is FIRST. and LAST. which allows you to check certain things if the observations are grouped together.
You need to explain further what you are looking for, and give small examples.
I want to find out which rows that are the same date in the previous rows and not same date. If all have the same date then i can use the max function to find maximal days of stay, if not the date are equals within the same ID and index_date, then i should take sum of days to find how many days there are in the health service.
How can I do that?
lag function only use the first rows and check for other rows, but this should stop when ID number changes.
Again, the request was to give some examples.
I believe this can all be done, but given the descriptions you provided, I can't give example code, I'm not even 100% sure what you mean.
for example this example in the picture down here:
Here is ID =P000027284 information that I want to take maximum of stay, ID=P005253910 is two registration that I want to have on two rows, sum for the sequence 1 to 3 and max difference on sequence 4. In addition,
sum the stay for ID=P000012625., You can see the data that I have on my server over here. I cannot send code. Must I use lag function for seq, tjtildato_refdager and other variables?
@user40 wrote:
Here is ID =P000027284 information that I want to take maximum of stay,
What is the variable name of stay?
ID=P005253910 is two registration that I want to have on two rows, sum for the sequence 1 to 3 and max difference on sequence 4.
Sum of what variable? Max difference of what variable? Difference between what 2 values? Why in one case you want sum and in the other case you want max difference? How do we know when to sum and when to difference?
Please, the problem needs much clearer and detailed description than what you have provided so far. Please describe the problem in detail without reference to SAS coding methods. Please take some time and write a clear and complete explanation.
variable name of stay is daydiff that are shown in the picture. If there are stays that are overlapping then I want to take out max daydiff of the ID. If there are stays after each other then i need to sum the variable daydiff. In addition, I need to take sum stays when the registered more than one day after each other and take max stays for the other record.
@user40 wrote:
variable name of stay is daydiff that are shown in the picture. If there are stays that are overlapping then I want to take out max daydiff of the ID. If there are stays after each other then i need to sum the variable daydiff. In addition, I need to take sum stays when the registered more than one day after each other and take max stays for the other record.
I don't know how to determine if "stays are overlapping". I don't know how to determine if stays are after each other. I don't know how to determine when "the registered more than one day after each other".
I'm going to stop here. I can't work like this.
I want you to write the entire problem clearly and completely, in one place. I do not want you to add a few more sentences to what you have previously written (which is what you are doing). I want the entire problem described in one place, with the data in the same place, so I don't have to scroll up and down to try to understand what you are talking about.
I also request that for the data you showed, you provide the desired output with explanation, which you can compute yourself without SAS and then type in the desired results.
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.