Hello,
I have a dataset with "people" as cases and a variable for "program start date" and I am attempting to write syntax to divide these people into fiscal quarters (first quarter is April 1st to June 30th) according to program start date. I also have multiple years (from 1998 to 2007)so I have several quarters. What is the best way to do this? I searched the archives but was unable to interpret some of the suggestions because they involved different date formats (my dates show up as "16-MAY-2004") and a set of Loop instructions which (sadly) I don't understand the principles of enough to modify it to my own case. Many thanks Diane |
What you want to do here is create a new variable which is the "divider" with categories equivalent to something like 1-APR-2004 to 30-JUN-2004, 1-JUL-2004 to 30-AUG-2004, etc.
There are 2 ways to go about this. You can code a series of IF (or DO IF) statements that look like this: IF (startdatevar >= DATE.MDY(4,1,2004) and startdatevar < DATE.MDY(7,1,2004)) quarterstart=1. IF (startdatevar >= DATE.MDY(7,1,2004) and startdatevar < DATE.MDY(10,1,2004)) quarterstart=2. ... Of you can use the Visual Binner to create a series of IF statements. You enter the upper boundary (e.g., 30-JUN-2004) as cutpoints. Notes: 1. Assumes that startdatevar is really a date variable and not a string. If it is a string, you need to get it into a date format first. 2. You need one comparison statement or cutpoint for each quarter in your data range.. 3. I just DATE.MDY for convenience here because if a the variable is a date variable, the format value 04/01/2004 == 1-APR-2004. 4. If you paste syntax from visual binner, you won't see formatted date values but very large numbers which are the internal representation of dates. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Diane Bartlett Sent: Sunday, February 18, 2007 3:29 PM To: [hidden email] Subject: Defining fiscal quarters Hello, I have a dataset with "people" as cases and a variable for "program start date" and I am attempting to write syntax to divide these people into fiscal quarters (first quarter is April 1st to June 30th) according to program start date. I also have multiple years (from 1998 to 2007)so I have several quarters. What is the best way to do this? I searched the archives but was unable to interpret some of the suggestions because they involved different date formats (my dates show up as "16-MAY-2004") and a set of Loop instructions which (sadly) I don't understand the principles of enough to modify it to my own case. Many thanks Diane |
In reply to this post by D Bartlett
Diane,
I see that ViAnn has already replied with the syntax for a series of compute statements. It seems that you could also use the extraction functions and perhaps the date.qyr function to create a quarter/fiscal year. In a manner like the following (untested). The idea is to create quarter as 1=Jan-Mar, 2=Apr-Jun, etc. and then recalculate it to reflect Your Fiscal years (which run July to June). Compute myquarter=xdate.quarter(mydate). Compute myyear=xdate.year(mydate). Do If myquarter > 1. compute myyear=myyear+1. compute myquarter=myquarter-1. Else if myquarter<2. compute myquarter=myquarter+3. End if. Compute FYQtr=date.qyr(myquarter,myyear). Then you would get Jan 2007=4 Q 2007 April 2007=1 Q 2008 June 2007=2 Q 2008 Sept 2007=3 Q 2008 XDATE.QUARTER. XDATE.QUARTER(datevalue). Numeric. Returns the quarter of the year (an integer between 1 and 4) from a numeric value in date format, as created by the DATE.xxx functions or read by one of the DATE input formats. XDATE.YEAR. XDATE.YEAR(datevalue). Numeric. Returns the year (as a four-digit integer) from a numeric value in date format, as created by the DATE.xxx functions or read by one of the DATE input formats. DATE.QYR. DATE.QYR(quarter,year). Numeric in date format. Returns a date value corresponding to the indicated quarter and year. To display this value correctly, assign it a DATE format. The arguments must be integers, with quarter between 1 and 4, and year a four-digit integer greater than 1582. Melissa The bubbling brook would lose its song if you removed the rocks. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Diane Bartlett Sent: Sunday, February 18, 2007 3:29 PM To: [hidden email] Subject: [SPSSX-L] Defining fiscal quarters Hello, I have a dataset with "people" as cases and a variable for "program start date" and I am attempting to write syntax to divide these people into fiscal quarters (first quarter is April 1st to June 30th) according to program start date. I also have multiple years (from 1998 to 2007)so I have several quarters. What is the best way to do this? I searched the archives but was unable to interpret some of the suggestions because they involved different date formats (my dates show up as "16-MAY-2004") and a set of Loop instructions which (sadly) I don't understand the principles of enough to modify it to my own case. Many thanks Diane PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
In a similar vein, I think this might work:
*if you don't want to keep quarter and year as separate variables use scratch variables:#quarter, #year. compute year=xdate.year(datevar). compute quarter=xdate.quarter(datevar)-1. do if quarter=0. compute quarter=4. compute year=year-1. end if. compute fiscalquarter=date.qyr(quarter, year). formats fiscalquarter (qyr6). ________________________________ From: SPSSX(r) Discussion on behalf of Melissa Ives Sent: Mon 2/19/2007 10:39 AM To: [hidden email] Subject: Re: Defining fiscal quarters Diane, I see that ViAnn has already replied with the syntax for a series of compute statements. It seems that you could also use the extraction functions and perhaps the date.qyr function to create a quarter/fiscal year. In a manner like the following (untested). The idea is to create quarter as 1=Jan-Mar, 2=Apr-Jun, etc. and then recalculate it to reflect Your Fiscal years (which run July to June). Compute myquarter=xdate.quarter(mydate). Compute myyear=xdate.year(mydate). Do If myquarter > 1. compute myyear=myyear+1. compute myquarter=myquarter-1. Else if myquarter<2. compute myquarter=myquarter+3. End if. Compute FYQtr=date.qyr(myquarter,myyear). Then you would get Jan 2007=4 Q 2007 April 2007=1 Q 2008 June 2007=2 Q 2008 Sept 2007=3 Q 2008 XDATE.QUARTER. XDATE.QUARTER(datevalue). Numeric. Returns the quarter of the year (an integer between 1 and 4) from a numeric value in date format, as created by the DATE.xxx functions or read by one of the DATE input formats. XDATE.YEAR. XDATE.YEAR(datevalue). Numeric. Returns the year (as a four-digit integer) from a numeric value in date format, as created by the DATE.xxx functions or read by one of the DATE input formats. DATE.QYR. DATE.QYR(quarter,year). Numeric in date format. Returns a date value corresponding to the indicated quarter and year. To display this value correctly, assign it a DATE format. The arguments must be integers, with quarter between 1 and 4, and year a four-digit integer greater than 1582. Melissa The bubbling brook would lose its song if you removed the rocks. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Diane Bartlett Sent: Sunday, February 18, 2007 3:29 PM To: [hidden email] Subject: [SPSSX-L] Defining fiscal quarters Hello, I have a dataset with "people" as cases and a variable for "program start date" and I am attempting to write syntax to divide these people into fiscal quarters (first quarter is April 1st to June 30th) according to program start date. I also have multiple years (from 1998 to 2007)so I have several quarters. What is the best way to do this? I searched the archives but was unable to interpret some of the suggestions because they involved different date formats (my dates show up as "16-MAY-2004") and a set of Loop instructions which (sadly) I don't understand the principles of enough to modify it to my own case. Many thanks Diane PRIVILEGED AND CONFIDENTIAL INFORMATION This transmittal and any attachments may contain PRIVILEGED AND CONFIDENTIAL information and is intended only for the use of the addressee. If you are not the designated recipient, or an employee or agent authorized to deliver such transmittals to the designated recipient, you are hereby notified that any dissemination, copying or publication of this transmittal is strictly prohibited. If you have received this transmittal in error, please notify us immediately by replying to the sender and delete this copy from your system. You may also call us at (309) 827-6026 for assistance. |
Free forum by Nabble | Edit this page |