count values for matched, sorted records

Moderators: statman, Analyst Techy, andris, Fierce, GerineL, Smash

AnnieLin
Posts: 4
Joined: Fri May 04, 2012 10:42 am

count values for matched, sorted records

Hi,
I'm struggling with my data...
I have a file with multiple records for certain persons. If a person (person A) has scored 1 for a certain variable (event) the records hereafter, which are sorted by date, should also score 1.
How do I do that?
AnnieLin
You do not have the required permissions to view the files attached to this post.
Penguin_Knight
Posts: 473
Joined: Thu Apr 05, 2012 5:58 pm

Re: count values for matched, sorted records

This may do:
* Sort case by ID and admission date .

* Make a new variable .
COMPUTE eventrecoded = event001 .

* Recode into a chain of 1 if event has already occurred .
IF patcod = lag(patcod) and lag(event001) = 1 eventrecoded = 1 .
EXECUTE .
AnnieLin
Posts: 4
Joined: Fri May 04, 2012 10:42 am

Re: count values for matched, sorted records

thanks for that , but it didn't really work. It gives a "1" in the record where event001=1 and the next one.
It should be in all the next lines with the same PATCOD (not necessarily where Event001=1)
I'm not familiar with the command LAG(variable), I should educate myself...Is there a clear explanation available for this on the net?
What I've done in the mean time is very complex and prone to mistakes (see below) . Can you see an obvious mistake?

*restructurate.
SORT CASES BY PATCOD Birthdate .
CASESTOVARS
/ID=PATCOD Birthdate
/GROUPBY=VARIABLE.

*than computed a new variabel
etc

*than restructurated it back
VARSTOCASES
/INDEX=Index1(4)
/KEEP=PATCOD
/NULL=DROP
/COUNT=casenr.

RECODE PREVV (0=0) (1 thru Highest=1) INTO Pr_event.
EXECUTE.
Penguin_Knight
Posts: 473
Joined: Thu Apr 05, 2012 5:58 pm

Re: count values for matched, sorted records

Oh, sorry. I made a mistake. Try this one:
* Sort case by ID and admission date .

* Make a new variable .
COMPUTE eventrecoded = event001 .
EXECUTE .

* Recode into a chain of 1 if event has already occurred .
IF patcod = lag(patcod) and lag(eventrecoded) = 1 eventrecoded = lag(eventrecoded) .
EXECUTE .
LAG is a function to borrow the data in the previous row.

See this syntax:
IF patcod = lag(patcod) and lag(eventrecoded) = 1 eventrecoded = lag(eventrecoded) .

Literally, it means if patcod on any row k is equal to patcod on row (k-1) AND the eventrecoded in the previous row is 1, then recode the eventrecoded in row k as 1.
AnnieLin
Posts: 4
Joined: Fri May 04, 2012 10:42 am

Re: count values for matched, sorted records

Thanks, I understand better now. It still didn't do exactly what I wanted, but I rewrote the syntax to the one below and now it seems to do the trick.
In the previous one, also alle events without a previous event were scored 1, which they shouldn't.

* Make a new variable .
COMPUTE eventrecoded = 0 .
EXECUTE .

* Recode into a chain of 1 if event has already occurred .
IF patcod = lag(patcod) and lag(event001) = 1 eventrecoded = 1.
EXECUTE .
IF patcod = lag(patcod) and lag(eventrecoded) = 1 eventrecoded = 1.
EXECUTE .
Penguin_Knight
Posts: 473
Joined: Thu Apr 05, 2012 5:58 pm

Re: count values for matched, sorted records

That's probably because I didn't understand the request correctly. I am glad that the problem was rectified.
LonnieKi
Posts: 4
Joined: Sat Jun 20, 2015 6:04 am
Contact:

count values for matched sorted records

If i had 2 open-e servers can i replicate in real time from one server to the other and in case of one failing manually switch over until you have the NAS failover sorted, would this work?

thanks

stevef1

Who is online

Users browsing this forum: No registered users and 2 guests