Extract Month from Date (11985 - 122018)

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

Extract Month from Date (11985 - 122018)

Chao yawo-2
Hello, I am working with the BRFS data.  I am interested in using a variable - Recent HIV testing.

The variable is recorded in month&date format as in  11985 (for January 1985) and 122018 (December 2018).

I want to create a new variable that just records the years from 1985 thru 2018.

I will appreciate any help to accomplish this.

thanks - cY
===================== 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: Extract Month from Date (11985 - 122018)

Ki Park
-If the information comes with date format you can extract by using:

COMPUTE yearBRFSS = xdate.year(HIVtesting_date).
EXECUTE.

-If the information is numeric variable:

ALTER TYPE HIVtesting_date (A6).
EXECUTE.

COMPUTE yearBRFSS = NUMBER(SUBSTR(HIVtesting_date,3,4), F4) .
EXECUTE .

ALTER TYPE HIVtesting_date (F6).
EXECUTE.

-If the information comes as a string, you will need to specify a little
more about it like length, leading or trailing spaces, etc.


Ki




--
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: Extract Month from Date (11985 - 122018)

CFong
In reply to this post by Chao yawo-2
Hello,

For your recorded format, couldn't you just divide by 10000 and truncate the result? For example,

compute month=trunc(date/10000).

On 11/29/2018 12:51 PM, Chao yawo wrote:
Hello, I am working with the BRFS data.  I am interested in using a variable - Recent HIV testing.

The variable is recorded in month&date format as in  11985 (for January 1985) and 122018 (December 2018).

I want to create a new variable that just records the years from 1985 thru 2018.

I will appreciate any help to accomplish this.

thanks - cY
===================== 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: Extract Month from Date (11985 - 122018)

CFong
If you want year, subtract out the month...

compute year=date-trunc(date/10000).

On 11/29/2018 2:30 PM, Chunki Fong wrote:
Hello,

For your recorded format, couldn't you just divide by 10000 and truncate the result? For example,

compute month=trunc(date/10000).

On 11/29/2018 12:51 PM, Chao yawo wrote:
Hello, I am working with the BRFS data.  I am interested in using a variable - Recent HIV testing.

The variable is recorded in month&date format as in  11985 (for January 1985) and 122018 (December 2018).

I want to create a new variable that just records the years from 1985 thru 2018.

I will appreciate any help to accomplish this.

thanks - cY
===================== 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: Extract Month from Date (11985 - 122018)

spss.giesel@yahoo.de

Does sth. like
COMPUTE year = MOD(RecentHIVtesting,10000).
work for you?

Mario Giesel
Munich, Germany



Am Donnerstag, 29. November 2018, 20:35:41 MEZ hat Chunki Fong <[hidden email]> Folgendes geschrieben:


If you want year, subtract out the month...

compute year=date-trunc(date/10000).

On 11/29/2018 2:30 PM, Chunki Fong wrote:
Hello,

For your recorded format, couldn't you just divide by 10000 and truncate the result? For example,

compute month=trunc(date/10000).

On 11/29/2018 12:51 PM, Chao yawo wrote:
Hello, I am working with the BRFS data.  I am interested in using a variable - Recent HIV testing.

The variable is recorded in month&date format as in  11985 (for January 1985) and 122018 (December 2018).

I want to create a new variable that just records the years from 1985 thru 2018.

I will appreciate any help to accomplish this.

thanks - cY
===================== 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
===================== 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: Extract Month from Date (11985 - 122018)

Maguin, Eugene
In reply to this post by Chao yawo-2

A missing piece of information is whether the variable (call it, Test) is string (a6) or numeric (f6.0). I guess it could also be MOYRw, where ‘w’ is the width, but the example in the book shows OCT 1990 and the examples given in the message are 11985 and 121985. If Test is numeric, I agree, month=trunc(Test/10000).

Gene Maguin

 

 

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Chao yawo
Sent: Thursday, November 29, 2018 12:52 PM
To: [hidden email]
Subject: Extract Month from Date (11985 - 122018)

 

Hello, I am working with the BRFS data.  I am interested in using a variable - Recent HIV testing.

 

The variable is recorded in month&date format as in  11985 (for January 1985) and 122018 (December 2018).

 

I want to create a new variable that just records the years from 1985 thru 2018.

 

I will appreciate any help to accomplish this.

 

thanks - cY

===================== 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: Extract Month from Date (11985 - 122018)

Robert L
In reply to this post by Chao yawo-2

I just tested the COMPUTE date2=NUMBER(date1,MOYR6), but it did not work. The MOYR format seems to require a “/” delimiter.  So (string) data formatted as “1/2015” would work.

 

The more “complete” date formats (SDATE,ADATE) for day, month and year can cope with both presence and absence of delimiters when converting string dates: NUMBER(‘20181130’,SDATE8) should work, just as NUMBER(‘2018/11/30’,SDATE10).

 

Robert

 

 

Från: SPSSX(r) Discussion [mailto:[hidden email]] För Maguin, Eugene
Skickat: den 29 november 2018 21:33
Till: [hidden email]
Ämne: Re: Extract Month from Date (11985 - 122018)

 

A missing piece of information is whether the variable (call it, Test) is string (a6) or numeric (f6.0). I guess it could also be MOYRw, where ‘w’ is the width, but the example in the book shows OCT 1990 and the examples given in the message are 11985 and 121985. If Test is numeric, I agree, month=trunc(Test/10000).

Gene Maguin

 

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