Date and Time Wizard

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Date and Time Wizard

Rajeshms
Hi All,

I have three variables Subject,Date and Visit. 

Subject     Date              Visit
1            1.2.2014             1
1             2.2.2014             2
1             3.2.2014             3
1             5.1.2014             4

2             1.2.2014            1
2              5.2.2014            2
2              6.2.2014            3
2              10.2.2014           4

3              11.2.2013           1
3              15.03.2013          2
3              16.04.2014          3
3              17.05.2014          4

like the above I have many cases. Now I need to flag the cases which is having lesser date than the previous visit /subject. The date should be increasing order as the visit increases. Kindly help me in getting the solution.I tried a lot but was not successful. Thanks a lot always.

Regards,

Rajesh M S


--
Regards,

Rajesh M S




===================== To manage your subscription to SPSSX-L, send a message to [hidden email] (not to SPSSX-L), with no body text except the command. To leave the list, send the command SIGNOFF SPSSX-L For a list of commands to manage subscriptions, send the command INFO REFCARD
Reply | Threaded
Open this post in threaded view
|

Re: Date and Time Wizard

David Marso
Administrator
Edify yourself with a gander at the LAG function!
----
Rajeshms wrote
Hi All,

I have three variables Subject,Date and Visit.

Subject     Date              Visit
1            1.2.2014             1
1             2.2.2014             2
1             3.2.2014             3
1             5.1.2014             4

2             1.2.2014            1
2              5.2.2014            2
2              6.2.2014            3
2              10.2.2014           4

3              11.2.2013           1
3              15.03.2013          2
3              16.04.2014          3
3              17.05.2014          4

like the above I have many cases. Now I need to flag the cases which is
having lesser date than the previous visit /subject. The date should be
increasing order as the visit increases. Kindly help me in getting the
solution.I tried a lot but was not successful. Thanks a lot always.

Regards,

Rajesh M S


--
Regards,

Rajesh M S

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"
Reply | Threaded
Open this post in threaded view
|

Re: Date and Time Wizard

Bruce Weaver
Administrator
In reply to this post by Rajeshms
What you want to do, I think, is flag subjects for whom the ranks of the dates are not the same as the visit numbers, right?  If so, try something like this:

RANK VARIABLES=Date (A) BY Subject
  /RANK
  /PRINT=NO
  /TIES=MEAN.

COMPUTE FLAG = RDate NE Visit.
FORMATS RDate FLAG (F1).

For your sample data set, subject 1 is flagged.

Subject       Date Visit RDate FLAG
 
    1   01.02.2014    1    2     1
    1   02.02.2014    2    3     1
    1   03.02.2014    3    4     1
    1   05.01.2014    4    1     1
    2   01.02.2014    1    1     0
    2   05.02.2014    2    2     0
    2   06.02.2014    3    3     0
    2   10.02.2014    4    4     0
    3   11.02.2013    1    1     0
    3   15.03.2013    2    2     0
    3   16.04.2014    3    3     0
    3   17.05.2014    4    4     0

HTH.

Rajeshms wrote
Hi All,

I have three variables Subject,Date and Visit.

Subject     Date              Visit
1            1.2.2014             1
1             2.2.2014             2
1             3.2.2014             3
1             5.1.2014             4

2             1.2.2014            1
2              5.2.2014            2
2              6.2.2014            3
2              10.2.2014           4

3              11.2.2013           1
3              15.03.2013          2
3              16.04.2014          3
3              17.05.2014          4

like the above I have many cases. Now I need to flag the cases which is
having lesser date than the previous visit /subject. The date should be
increasing order as the visit increases. Kindly help me in getting the
solution.I tried a lot but was not successful. Thanks a lot always.

Regards,

Rajesh M S


--
Regards,

Rajesh M S

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: Date and Time Wizard

David Marso
Administrator

This is what I was thinking.
I hadn't considered RANK, but good thought!
DATA LIST LIST /Subject   (F1)    Date (Date) Visit (F1).
BEGIN DATA
    1   01.02.2014    1  
    1   02.02.2014    2  
    1   03.02.2014    3  
    1   05.01.2014    4  
    2   01.02.2014    1  
    2   05.02.2014    2  
    2   06.02.2014    3  
    2   10.02.2014    4  
    3   11.02.2013    1    
    3   15.03.2013    2  
    3   16.04.2014    3  
    3   17.05.2014    4  
END DATA.
SORT CASES BY Subject Visit /*likely optional if data are already properly ordered */.
COMPUTE recflag=SUBJECT EQ LAG(Subject) AND Date LT LAG(Date) /* Flag offending record(s) */.
AGGREGATE OUTFILE * MODE ADDVARIABLES/BREAK=Subject/Caseflag=MAX(recflag) /* reate global flag for bad cases */..
Bruce Weaver wrote
What you want to do, I think, is flag subjects for whom the ranks of the dates are not the same as the visit numbers, right?  If so, try something like this:

RANK VARIABLES=Date (A) BY Subject
  /RANK
  /PRINT=NO
  /TIES=MEAN.

COMPUTE FLAG = RDate NE Visit.
FORMATS RDate FLAG (F1).

For your sample data set, subject 1 is flagged.

Subject       Date Visit RDate FLAG
 
    1   01.02.2014    1    2     1
    1   02.02.2014    2    3     1
    1   03.02.2014    3    4     1
    1   05.01.2014    4    1     1
    2   01.02.2014    1    1     0
    2   05.02.2014    2    2     0
    2   06.02.2014    3    3     0
    2   10.02.2014    4    4     0
    3   11.02.2013    1    1     0
    3   15.03.2013    2    2     0
    3   16.04.2014    3    3     0
    3   17.05.2014    4    4     0

HTH.

Rajeshms wrote
Hi All,

I have three variables Subject,Date and Visit.

Subject     Date              Visit
1            1.2.2014             1
1             2.2.2014             2
1             3.2.2014             3
1             5.1.2014             4

2             1.2.2014            1
2              5.2.2014            2
2              6.2.2014            3
2              10.2.2014           4

3              11.2.2013           1
3              15.03.2013          2
3              16.04.2014          3
3              17.05.2014          4

like the above I have many cases. Now I need to flag the cases which is
having lesser date than the previous visit /subject. The date should be
increasing order as the visit increases. Kindly help me in getting the
solution.I tried a lot but was not successful. Thanks a lot always.

Regards,

Rajesh M S


--
Regards,

Rajesh M S

=====================
To manage your subscription to SPSSX-L, send a message to
[hidden email] (not to SPSSX-L), with no body text except the
command. To leave the list, send the command
SIGNOFF SPSSX-L
For a list of commands to manage subscriptions, send the command
INFO REFCARD
Please reply to the list and not to my personal email.
Those desiring my consulting or training services please feel free to email me.
---
"Nolite dare sanctum canibus neque mittatis margaritas vestras ante porcos ne forte conculcent eas pedibus suis."
Cum es damnatorum possederunt porcos iens ut salire off sanguinum cliff in abyssum?"