BookmarkSubscribeRSS Feed
user40
Calcite | Level 5

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?

7 REPLIES 7
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
user40
Calcite | Level 5

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. 

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
user40
Calcite | Level 5

for example this example in the picture down here: 

 

table2.JPG

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?

 

PaigeMiller
Diamond | Level 26

@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.

 

 

 

--
Paige Miller
user40
Calcite | Level 5

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. 

 

 

 

PaigeMiller
Diamond | Level 26

@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.

 

 

--
Paige Miller

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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