Selecting date range for multiple variables

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

Selecting date range for multiple variables

Erin
I am hoping someone on here may be able to help me with some syntax.
I would like a filter variable for anyone who has visited a service within a
specific date range.
e.g. filter people who attended the service between June 2017 - June 2018.

I have filtered those who first visited the service between these dates:

USE ALL.
COMPUTE filter_first_2016_2017=
RANGE(OS_DATE_first,DATE.MDY(7,1,2016),DATE.MDY(6,30,2017)).
VARIABLE LABELS filter_first_2016_2017 'First OS in 2016-2017 (FILTER)'.
VALUE LABELS filter_first_2016_2017 0 'No' 1 '2016-2017'.
FORMATS filter_first_2016_2017 (f1.0).
FILTER BY filter_first_2016_2017.
EXECUTE.
FILTER OFF.
USE ALL.

But I cannot figure out how to do this across multiple 'visit date'
variables (I have 30: OS_DATE1 TO OS_DATE30)
The date variables are in SDATE10 format.

Thank you in advance!









--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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: Selecting date range for multiple variables

David Marso
Administrator
See DO REPEAT for this.

DO REPEAT filt=filter_2016_2017_01 TO filter_2016_2017_30 /OS_Date=OS_DATE1
TO OS_DATE30.
COMPUTE date2016=DATE.MDY(7,01,2016).
COMPUTE date2017=DATE.MDY(6,30,2017).
COMPUTE filt=RANGE(OS_DATE,Date2016),Date2017).
END REPEAT.
VALUE LABELS filter_2016_2017_01 TO filter_2016_2017_30  0 'No' 1
'2016-2017'.

Why are you doing this?
Turning on the filter not running anything and then turning the filter off?
FILTER BY filter_first_2016_2017.
EXECUTE.
FILTER OFF.
USE ALL.


quote author="Erin">
I am hoping someone on here may be able to help me with some syntax.
I would like a filter variable for anyone who has visited a service within a
specific date range.
e.g. filter people who attended the service between June 2017 - June 2018.

I have filtered those who first visited the service between these dates:

USE ALL.
COMPUTE filter_first_2016_2017=
RANGE(OS_DATE_first,DATE.MDY(7,1,2016),DATE.MDY(6,30,2017)).
VARIABLE LABELS filter_first_2016_2017 'First OS in 2016-2017 (FILTER)'.
VALUE LABELS filter_first_2016_2017 0 'No' 1 '2016-2017'.
FORMATS filter_first_2016_2017 (f1.0).
FILTER BY filter_first_2016_2017.
EXECUTE.
FILTER OFF.
USE ALL.

But I cannot figure out how to do this across multiple 'visit date'
variables (I have 30: OS_DATE1 TO OS_DATE30)
The date variables are in SDATE10 format.

Thank you in advance!









--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
To manage your subscription to SPSSX-L, send a message to
LISTSERV@.UGA (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?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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: Selecting date range for multiple variables

David Marso
Administrator
If you need to only create a single filter to cover ALL 30 of the possible
visits use:
This is a bit more efficient than previous post -NOTE CORRECTIONS IN
ORIGINAL-

VECTOR OS_Date=OS_DATE1 TO OS_DATE30.  

DO IF $CASENUM EQ 1.
+  COMPUTE #date2016=DATE.MDY(7,01,2016).
+  COMPUTE #date2017=DATE.MDY(6,30,2017).
END IF.

COMPUTE filter_2016_2017=0.
LOOP #=1 TO 30.
+  COMPUTE filter_2016_2017=RANGE(OS_DATE(#),#Date2016,#Date2017).
END LOOP IF filter_2016_2017.
VALUE LABELS filter_2016_2017  0 'No' 1 '2016-2017'.


David Marso wrote

> See DO REPEAT for this.
>
>
> DO IF $CASENUM EQ 1.
> +  COMPUTE #date2016=DATE.MDY(7,01,2016).
> +  COMPUTE #date2017=DATE.MDY(6,30,2017).
> END IF.
>
> DO REPEAT filt=filter_2016_2017_01 TO filter_2016_2017_30
>                       /OS_Date=OS_DATE1 TO OS_DATE30.
> +  COMPUTE filt=RANGE(OS_DATE,#date2016,#date2017).
> END REPEAT.
> VALUE LABELS
>     filter_2016_2017_01 TO filter_2016_2017_30  0 'No' 1 '2016-2017'.
>
> Why are you doing this?
> Turning on the filter not running anything and then turning the filter
> off?
> FILTER BY filter_first_2016_2017.
> EXECUTE.
> FILTER OFF.
> USE ALL.
>
>
> quote author="Erin">
> I am hoping someone on here may be able to help me with some syntax.
> I would like a filter variable for anyone who has visited a service within
> a
> specific date range.
> e.g. filter people who attended the service between June 2017 - June 2018.
>
> I have filtered those who first visited the service between these dates:
>
> USE ALL.
> COMPUTE filter_first_2016_2017=
> RANGE(OS_DATE_first,DATE.MDY(7,1,2016),DATE.MDY(6,30,2017)).
> VARIABLE LABELS filter_first_2016_2017 'First OS in 2016-2017 (FILTER)'.
> VALUE LABELS filter_first_2016_2017 0 'No' 1 '2016-2017'.
> FORMATS filter_first_2016_2017 (f1.0).
> FILTER BY filter_first_2016_2017.
> EXECUTE.
> FILTER OFF.
> USE ALL.
>
> But I cannot figure out how to do this across multiple 'visit date'
> variables (I have 30: OS_DATE1 TO OS_DATE30)
> The date variables are in SDATE10 format.
>
> Thank you in advance!
>
>
>
>
>
>
>
>
>
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to
> LISTSERV@.UGA (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?"
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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?"
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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: Selecting date range for multiple variables

Bruce Weaver
Administrator
Those who are not familiar with scratch variables (i.e., variables that start
with #) may benefit from this piece of information in the CSR manual:

* Scratch variables are not reinitialized when a new case is read. Their
values are always carried across cases. (So using a scratch variable can be
essentially equivalent to using the LEAVE command.)

Source:
https://www.ibm.com/support/knowledgecenter/en/SSLVMB_25.0.0/statistics_reference_project_ddita/spss/base/syn_variables_scratch_variables.html

So where David's code sets the values of #date2016 and #date2017 on row 1 of
the dataset, those values are carried across to all cases.  

HTH.



David Marso wrote

> If you need to only create a single filter to cover ALL 30 of the possible
> visits use:
> This is a bit more efficient than previous post -NOTE CORRECTIONS IN
> ORIGINAL-
>
> VECTOR OS_Date=OS_DATE1 TO OS_DATE30.  
>
> DO IF $CASENUM EQ 1.
> +  COMPUTE #date2016=DATE.MDY(7,01,2016).
> +  COMPUTE #date2017=DATE.MDY(6,30,2017).
> END IF.
>
> COMPUTE filter_2016_2017=0.
> LOOP #=1 TO 30.
> +  COMPUTE filter_2016_2017=RANGE(OS_DATE(#),#Date2016,#Date2017).
> END LOOP IF filter_2016_2017.
> VALUE LABELS filter_2016_2017  0 'No' 1 '2016-2017'.
>
>
> David Marso wrote
>> See DO REPEAT for this.
>>
>>
>> DO IF $CASENUM EQ 1.
>> +  COMPUTE #date2016=DATE.MDY(7,01,2016).
>> +  COMPUTE #date2017=DATE.MDY(6,30,2017).
>> END IF.
>>
>> DO REPEAT filt=filter_2016_2017_01 TO filter_2016_2017_30
>>                       /OS_Date=OS_DATE1 TO OS_DATE30.
>> +  COMPUTE filt=RANGE(OS_DATE,#date2016,#date2017).
>> END REPEAT.
>> VALUE LABELS
>>     filter_2016_2017_01 TO filter_2016_2017_30  0 'No' 1 '2016-2017'.
>>
>> Why are you doing this?
>> Turning on the filter not running anything and then turning the filter
>> off?
>> FILTER BY filter_first_2016_2017.
>> EXECUTE.
>> FILTER OFF.
>> USE ALL.
>>
>>
>> quote author="Erin">
>> I am hoping someone on here may be able to help me with some syntax.
>> I would like a filter variable for anyone who has visited a service
>> within
>> a
>> specific date range.
>> e.g. filter people who attended the service between June 2017 - June
>> 2018.
>>
>> I have filtered those who first visited the service between these dates:
>>
>> USE ALL.
>> COMPUTE filter_first_2016_2017=
>> RANGE(OS_DATE_first,DATE.MDY(7,1,2016),DATE.MDY(6,30,2017)).
>> VARIABLE LABELS filter_first_2016_2017 'First OS in 2016-2017 (FILTER)'.
>> VALUE LABELS filter_first_2016_2017 0 'No' 1 '2016-2017'.
>> FORMATS filter_first_2016_2017 (f1.0).
>> FILTER BY filter_first_2016_2017.
>> EXECUTE.
>> FILTER OFF.
>> USE ALL.
>>
>> But I cannot figure out how to do this across multiple 'visit date'
>> variables (I have 30: OS_DATE1 TO OS_DATE30)
>> The date variables are in SDATE10 format.
>>
>> Thank you in advance!
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>> LISTSERV@.UGA (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?"
>> --
>> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>>
>> =====================
>> To manage your subscription to SPSSX-L, send a message to
>
>> LISTSERV@.UGA
>
>>  (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?"
> --
> Sent from: http://spssx-discussion.1045642.n5.nabble.com/
>
> =====================
> To manage your subscription to SPSSX-L, send a message to

> LISTSERV@.UGA

>  (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
[hidden email]
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

NOTE: My Hotmail account is not monitored regularly.
To send me an e-mail, please use the address shown above.

--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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: Selecting date range for multiple variables

Art Kendall
However, for quality assurance, the LEAVE would be implicit.  
Using LEAVE or a syntax comment about the implicit  LEAVE would be clearer.



-----
Art Kendall
Social Research Consultants
--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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
Art Kendall
Social Research Consultants
Reply | Threaded
Open this post in threaded view
|

Re: Selecting date range for multiple variables

Erin
In reply to this post by David Marso
Thank you David, that worked perfectly
Didn't mean to catch the filter off syntax...just habit to turn them all
off.





--
Sent from: http://spssx-discussion.1045642.n5.nabble.com/

=====================
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