exchange data (dates)

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

exchange data (dates)

gc_edelman
Hi, I have a problem with a syntaxis. I am working with dates: entry date
(fch_entr) and departure date (fch_sal).

I have three data with 2 different problems:
1. The year in the departure date is 2017. It must be 2018.
2. On the other hand, the entry date is on the departure date and viceversa.

I tried this command:

IF (fch_entr='17/Jan/2018' & fch_sal='18/Jan/2017') fch_sal='18/Jan/2018'.
IF (fch_entr='01/oct/2018' & fch_sal='30/sep/2018') fch_entr='30/sep/2018'.
IF (fch_entr='01/oct/2018' & fch_sal='30/sep/2018') fch_sal='01/oct/2018'.
IF (fch_entr='12/mar/2018' & fch_sal='13/feb/2018') fch_entr='13/feb/2018'.
IF (fch_entr='12/mar/2018' & fch_sal='13/feb/2018') fch_sal='12/mar/2018'.
execute.

Wich does not work, I would like your help, please.




--
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: exchange data (dates)

Art Kendall
assuming that the input string already exists this syntax snippet shows some
things you could do?

Is there a reason you do not want to treat the variable as a date?

Would periods in a European date EDATE display format be acceptable?

new file.
data list list /MyDate (a20).
begin data
"01 / 22 / 1999"
"12 / 25 / 2013"
7/4/2010
03/22/1955
6/1/2017
12/25/2017
end data.

string MyOldString (a20).
compute MyOldString = MyDate.
alter type MyDate (a=adate10).
list.
formats MyDate (date10).
list.
formats Mydate (edate10).
list.
numeric NewDate (edate10).
do if xdate.year(Mydate) eq 2017.
    compute newdate = datesum(Mydate,1,"years").
ELSE.
    compute newdate = MyDate.
end if.
list.






-----
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: exchange data (dates)

Rich Ulrich
In reply to this post by gc_edelman
I see "Jan" and "Jan" but all other months start in lower case letters.
This unusual inconsistency makes me wonder what else is inconsistent.

Do you really have data in A10 format, or are you trying to match "dates"
in date-format with dates read as A10? - that will not work.  Art suggests
going to date-format, and how to work with that by adding one year.

The two cases where you want to switch "entry" with "departure" need to
use DO IF -- the second set of IFs won't match after Entry has been changed.

For sake of documentation, I would probably want to use DO or DO IF where
I match the unique Case ID (assuming that there is one).

--
Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of gc_edelman <[hidden email]>
Sent: Wednesday, August 21, 2019 5:16 PM
To: [hidden email] <[hidden email]>
Subject: exchange data (dates)
 
Hi, I have a problem with a syntaxis. I am working with dates: entry date
(fch_entr) and departure date (fch_sal).

I have three data with 2 different problems:
1. The year in the departure date is 2017. It must be 2018.
2. On the other hand, the entry date is on the departure date and viceversa.

I tried this command:

IF (fch_entr='17/Jan/2018' & fch_sal='18/Jan/2017') fch_sal='18/Jan/2018'.
IF (fch_entr='01/oct/2018' & fch_sal='30/sep/2018') fch_entr='30/sep/2018'.
IF (fch_entr='01/oct/2018' & fch_sal='30/sep/2018') fch_sal='01/oct/2018'.
IF (fch_entr='12/mar/2018' & fch_sal='13/feb/2018') fch_entr='13/feb/2018'.
IF (fch_entr='12/mar/2018' & fch_sal='13/feb/2018') fch_sal='12/mar/2018'.
execute.

Wich does not work, I would like your help, please.




--
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
===================== 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: exchange data (dates)

PRogman
In reply to this post by gc_edelman
What data type are fch_entr and fch_sal? If type 'string' then you could
manipulate the strings o replace the year. In this case I prefer to work
with date format which also would allow you to compare order. Use the
XDATE.xxx function to extract parts of the date value, and DATE.xxx to
aggregate a date value from parts. See Reference Manual for details.
When you switch values of two variables you usually need a temporary
variable to hold the value.

/PR

* Assume date variables are type 'string' *.
DATA LIST list /
id fch_entr fch_sal (F8.0 2A11).
BEGIN DATA
1  '17/Jan/2018'  '18/Jan/2017'
2  '01/oct/2018'  '30/sep/2018'
4  '12/mar/2018'  '13/feb/2018'
END DATA.
EXECUTE.

LIST ALL.

* Convert string variable to date variable *.
ALTER TYPE fch_entr (DATE11) /PRINT NONE.
ALTER TYPE fch_sal  (DATE11) /PRINT NONE.

* My preferred date format *.
FORMATS fch_entr  fch_sal  (SDATE10).

* Replace error in Year: 2017 -> 2018 in both variables *.
DO REPEAT d = fch_entr  fch_sal.
  IF (XDATE.YEAR(d) EQ 2017) d = DATE.DMY(XDATE.MDAY(d), XDATE.MONTH(d),
2018).
END REPEAT.

* Switch date value if not chronological *.
DO IF (fch_sal LT fch_entr).
  COMPUTE #d       = fch_sal.
  COMPUTE fch_sal  = fch_entr.
  COMPUTE fch_entr = #d.
END IF.

LIST ALL.



gc_edelman wrote

> Hi, I have a problem with a syntaxis. I am working with dates: entry date
> (fch_entr) and departure date (fch_sal).
>
> I have three data with 2 different problems:
> 1. The year in the departure date is 2017. It must be 2018.
> 2. On the other hand, the entry date is on the departure date and
> viceversa.
>
> I tried this command:
>
> IF (fch_entr='17/Jan/2018' & fch_sal='18/Jan/2017') fch_sal='18/Jan/2018'.
> IF (fch_entr='01/oct/2018' & fch_sal='30/sep/2018')
> fch_entr='30/sep/2018'.
> IF (fch_entr='01/oct/2018' & fch_sal='30/sep/2018') fch_sal='01/oct/2018'.
> IF (fch_entr='12/mar/2018' & fch_sal='13/feb/2018')
> fch_entr='13/feb/2018'.
> IF (fch_entr='12/mar/2018' & fch_sal='13/feb/2018') fch_sal='12/mar/2018'.
> execute.
>
> Wich does not work, I would like your help, please.
>
> --
> 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





--
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: exchange data (dates)

gc_edelman
Thank to all of you...! I solved it..!



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