Date format

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

Date format

Elin_G
Hello everyone!

I need help with the date format.

I "select cases" between two different dates in a file (date format: 12-Jan-2007 16:16:01)

In my syntax , I am using:

DEFINE !STARTDATE ()
      DATE.DMY(01,03,2011)
!ENDDEFINE.

DEFINE !SLUTDATE ()
      DATE.DMY(31,03,2011)      
!ENDDEFINE.

SELECT IF(REG_TIDPUNKT>=!STARTDATE & REG_TIDPUNKT<=!ENDDATE).


But the problem with this is that I have both the date and time in "REG_TIDSPUNKT" so when I do this so I do not get the last day of the month. So thinking that I'll just pick out the month of March but how do I do? What date format should I use?
Reply | Threaded
Open this post in threaded view
|

Re: Date format

Andy W
There are other solutions, but I typically use the first day of the next month and the use a less than, e.g.

DEFINE !STARTDATE ()
      DATE.DMY(01,03,2011)
!ENDDEFINE.

DEFINE !ENDDATE ()
      DATE.DMY(01,04,2011)      
!ENDDEFINE.

SELECT IF(REG_TIDPUNKT>=!STARTDATE & REG_TIDPUNKT< !ENDDATE).

You may also be interested in the RANGE function, and the XDATE.DATE extractor function.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Date format

Elin_G
Hey!

Yes, absolutely, I can use the first day of the next month, but I do not want to do. But I found another function.

DEFINE !START ()
      DATE.MOYR (06, 2015)
!ENDDEFINE.

DEFINE !SLUT ()
       DATE.MOYR(06, 2015)
!ENDDEFINE.

SELECT IF(REG_TIDPUNKT>=!START & REG_TIDPUNKT<=!SLUT).
EXECUTE.



But it does not seem to work as I want, what have I done wrong?
Reply | Threaded
Open this post in threaded view
|

Re: Date format

Andy W
That is equivalent to selecting the first of the month. Logically how do you expect !START and !END to have different values if you supply them the same input?

If you don't want to use the first day on the following month, then see the XDATE.DATE function I mentioned. If you use XDATE.DATE(REG_TIDPUNKT) it strips the time portion from REG_TIDPUNKT, so the less than or equal to should work.

So something like

RANGE(XDATE.DATE(REG_TIDPUNKT),!START,!END).

would work in the selection criteria.
Andy W
apwheele@gmail.com
http://andrewpwheeler.wordpress.com/
Reply | Threaded
Open this post in threaded view
|

Re: Date format

David Marso
Administrator
In reply to this post by Elin_G
Have you tried Andy's suggestion of XDATE.DATE?

If using the first day of the next month use LT (<) rather than LE (<=) on comparison.

"But it does not seem to work as I want, what have I done wrong?"
Gee, I don't know.  Maybe post an example of how it didn't work as you wanted?
-----------------------------

Elin_G wrote
Hey!

Yes, absolutely, I can use the first day of the next month, but I do not want to do. But I found another function.

DEFINE !START ()
      DATE.MOYR (06, 2015)
!ENDDEFINE.

DEFINE !SLUT ()
       DATE.MOYR(06, 2015)
!ENDDEFINE.

SELECT IF(REG_TIDPUNKT>=!START & REG_TIDPUNKT<=!SLUT).
EXECUTE.



But it does not seem to work as I want, what have I done wrong?
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 format

Elin_G

Hey!

Previously held XDATE.DATE my syntax but do not want it so long as the runs take a very long time.

Here's the code:
COMPUTE AR1 = # XDATE.YEAR (REG_TIDPUNKT).
COMPUTE # Man1 = XDATE.MONTH (REG_TIDPUNKT).
COMPUTE Inman = (# AR1 * 100 + # MAN1).
VARIABLE LABELS Inman 'cases received (monthly)'.
VARIABLE WIDTH Inman (8).
FORMATS Inman (F8.0).
VARIABLE ALIGNMENT Inman (center).
EXECUTE.


What happens is that I do not get any data in the data file, so wondering if I'm doing something wrong
Reply | Threaded
Open this post in threaded view
|

Re: Date format

David Marso
Administrator
If this is exactly the code you submitted then I can see 4 reasons why things would screw up (all involving placement of the # symbol).
Before you had these in macros, now you are changing things on us.

Elin_G wrote
Hey!

Previously held XDATE.DATE my syntax but do not want it so long as the runs take a very long time.

Here's the code:
COMPUTE AR1 = # XDATE.YEAR (REG_TIDPUNKT).
COMPUTE # Man1 = XDATE.MONTH (REG_TIDPUNKT).
COMPUTE Inman = (# AR1 * 100 + # MAN1).
VARIABLE LABELS Inman 'cases received (monthly)'.
VARIABLE WIDTH Inman (8).
FORMATS Inman (F8.0).
VARIABLE ALIGNMENT Inman (center).
EXECUTE.


What happens is that I do not get any data in the data file, so wondering if I'm doing something wrong
Elin_G wrote
Hey!

Previously held XDATE.DATE my syntax but do not want it so long as the runs take a very long time.

Here's the code:
COMPUTE AR1 = # XDATE.YEAR (REG_TIDPUNKT).
COMPUTE # Man1 = XDATE.MONTH (REG_TIDPUNKT).
COMPUTE Inman = (# AR1 * 100 + # MAN1).
VARIABLE LABELS Inman 'cases received (monthly)'.
VARIABLE WIDTH Inman (8).
FORMATS Inman (F8.0).
VARIABLE ALIGNMENT Inman (center).
EXECUTE.


What happens is that I do not get any data in the data file, so wondering if I'm doing something wrong
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 format

Maguin, Eugene
In reply to this post by Elin_G
Other problems aside, I think you have a syntax error in the two lines marked with an '>>. The error is a space following the '#'
Character. Also, the line for the AR1 computation is commented out.  Aren't you getting error statements?  Why do you have all the code between '*' characters?
Gene Maguin


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Elin_G
Sent: Wednesday, July 22, 2015 8:53 AM
To: [hidden email]
Subject: Re: Date format

Hey!

Previously held XDATE.DATE my syntax but do not want it so long as the runs take a very long time.

Here's the code:
*COMPUTE AR1 = # XDATE.YEAR (REG_TIDPUNKT).
>>COMPUTE # Man1 = XDATE.MONTH (REG_TIDPUNKT).
>>COMPUTE Inman = (# AR1 * 100 + # MAN1).
VARIABLE LABELS Inman 'cases received (monthly)'.
VARIABLE WIDTH Inman (8).
FORMATS Inman (F8.0).
VARIABLE ALIGNMENT Inman (center).
EXECUTE.*

What happens is that I do not get any data in the data file, so wondering if I'm doing something wrong



--
View this message in context: http://spssx-discussion.1045642.n5.nabble.com/Date-format-tp5730228p5730236.html
Sent from the SPSSX Discussion mailing list archive at 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

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

Elin_G
Hello again !

I do not want to use: XDATE.DATE.

I want to use the:

DEFINE !START ()
      DATE.MOYR (06, 2015)
!ENDDEFINE.

DEFINE !SLUT ()
       DATE.MOYR(06, 2015)
!ENDDEFINE.

SELECT IF(REG_TIDPUNKT>=!START & REG_TIDPUNKT<=!SLUT).
EXECUTE.

But do not submit any data. So where is it wrong? Did this work for anyone else?
Reply | Threaded
Open this post in threaded view
|

Re: Date format

Bruce Weaver
Administrator
In reply to this post by Elin_G
If my ESPss is working, REG_TIDPUNKT is a date variable, and you want to select cases where REG_TIDPUNKT falls in the month June, 2015.  Is that right?  Does this do what you want?

SELECT IF
 (XDATE.MONTH(REG_TIDPUNKT) EQ 6) and
 (XDATE.YEAR(REG_TIDPUNKT) EQ 2015).
EXECUTE.


(My apologies to other respondents for handing over a fish.  I just couldn't take it any more!)  


Elin_G wrote
Hey!

Yes, absolutely, I can use the first day of the next month, but I do not want to do. But I found another function.

DEFINE !START ()
      DATE.MOYR (06, 2015)
!ENDDEFINE.

DEFINE !SLUT ()
       DATE.MOYR(06, 2015)
!ENDDEFINE.

SELECT IF(REG_TIDPUNKT>=!START & REG_TIDPUNKT<=!SLUT).
EXECUTE.



But it does not seem to work as I want, what have I done wrong?
--
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 format

Elin_G

Hello again!

No it will not work when I at the top of the syntax defines the dates. Therefore these:


DEFINE !START ()
      DATE.MOYR (06, 2015)
!ENDDEFINE.

DEFINE !SLUT ()
       DATE.MOYR(06, 2015)
!ENDDEFINE.

Is there no one who knows what's wrong?
Reply | Threaded
Open this post in threaded view
|

Re: Date format

David Marso
Administrator
You haven't submitted any examples of what does and doesn't work.
So start at the top and create some simple example and someone might bother to look at it.
--
Elin_G wrote
Hello again!

No it will not work when I at the top of the syntax defines the dates. Therefore these:


DEFINE !START ()
      DATE.MOYR (06, 2015)
!ENDDEFINE.

DEFINE !SLUT ()
       DATE.MOYR(06, 2015)
!ENDDEFINE.

Is there no one who knows what's wrong?
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 format

Bruce Weaver
Administrator
In reply to this post by Elin_G
I've come back to your first post in this thread to point out that you define a macro called !SLUTDATE, but then later insert !ENDDATE where !SLUTDATE would be expected.  If you fix that problem, does it work as you intended?  E.g., here is a small demo:

DEFINE !STARTDATE ()
      DATE.DMY(01,03,2011)
!ENDDEFINE.

DEFINE !SLUTDATE ()
      DATE.DMY(31,03,2011)      
!ENDDEFINE.

* Generate some data to illustrate.
NEW FILE.
DATASET CLOSE all.
DATA LIST list / REG_TIDPUNKT(DATE11).
BEGIN DATA
28-FEB-2011
1-MAR-2011
15-MAR-2011
30-MAR-2011
31-MAR-2011
1-APR-2011
END DATA.
LIST.

SELECT IF(REG_TIDPUNKT>=!STARTDATE & REG_TIDPUNKT<=!SLUTDATE).
LIST.

OUTPUT from the first LIST command:

REG_TIDPUNKT
 
 28-FEB-2011
 01-MAR-2011
 15-MAR-2011
 30-MAR-2011
 31-MAR-2011
 01-APR-2011

Number of cases read:  6    Number of cases listed:  6

Output from the second LIST command:

REG_TIDPUNKT
 
 01-MAR-2011
 15-MAR-2011
 30-MAR-2011
 31-MAR-2011
 
Number of cases read:  4    Number of cases listed:  4

Elin_G wrote
Hello everyone!

I need help with the date format.

I "select cases" between two different dates in a file (date format: 12-Jan-2007 16:16:01)

In my syntax , I am using:

DEFINE !STARTDATE ()
      DATE.DMY(01,03,2011)
!ENDDEFINE.

DEFINE !SLUTDATE ()
      DATE.DMY(31,03,2011)      
!ENDDEFINE.

SELECT IF(REG_TIDPUNKT>=!STARTDATE & REG_TIDPUNKT<=!ENDDATE).


But the problem with this is that I have both the date and time in "REG_TIDSPUNKT" so when I do this so I do not get the last day of the month. So thinking that I'll just pick out the month of March but how do I do? What date format should I use?
--
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 format

PRogman
In reply to this post by Elin_G
How was your data timepoints entered into SPSS? What type of variable is REG_TIDPUNKT? Is it a string? It should be of type Date.
Apart from your changing variable names (!SLUTDATE ->!ENDDATE) which never could have worked, the program logic is correct. Obviously this was not the code you run, or you would have had a macro definition error.
The RANGE(test,lo,hi[,lo,hi,..]) command is well suited to your logic in your example.
Further, it may help to translate your descriptive variable names into English. Readability and program logic is improved.

Try

ALTER TYPE Reg_Tidpunkt (DATETIME20).

and then run your syntax.

HTH, PRogman