|
I have a date variable which is imbedded in a string (length is A15)
shown below. I need to either extract the date or remove the trailing " 0:00" to convert the left portion into a date. Any suggestions greatly welcomed, thanks 10/13/1987 0:00 7/23/1991 0:00 12/11/1954 0:00 David ===================== 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 |
|
Hi David!
It would be easier to modify the GET DATA syntax (if you used that command). But the code below works as well. The leading zero of single-digit days are missing, which makes it a bit more difficult. Cheers!! Albert-Jan data list free / old (a15). begin data '10/13/1987 0:00' '7/23/1991 0:00' '12/11/1954 0:00' end data. compute #slash1 = index(old, "/"). compute #slash2 = rindex(old, "/"). compute new = date.mdy( number(substr(old, 1, #slash1-1), n2), number(substr(old, #slash1+1, #slash2-1), n2), number(substr(old, #slash2+1, 4), n4)). formats new (adate12). --- On Fri, 2/27/09, David Wright <[hidden email]> wrote: > From: David Wright <[hidden email]> > Subject: remove trailing alphas from var length string > To: [hidden email] > Date: Friday, February 27, 2009, 1:08 PM > I have a date variable which is imbedded in a string (length > is A15) > shown below. I need to either extract the date or remove > the trailing " > 0:00" to convert the left portion into a date. Any > suggestions greatly > welcomed, thanks > > > 10/13/1987 0:00 > 7/23/1991 0:00 > 12/11/1954 0:00 > > > David > > ===================== > 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 |
|
Assuming there's a space between the date and time:
data list free / old (a15). begin data '10/13/1987 0:00' '7/23/1991 0:00' '12/11/1954 0:00' end data. string #temp (a10). compute #temp=substr(old, 1, index(old, " ")-1). compute new=number(#temp, adate10). formats new (adate10). list. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Albert-jan Roskam Sent: Friday, February 27, 2009 7:00 AM To: [hidden email] Subject: Re: remove trailing alphas from var length string Hi David! It would be easier to modify the GET DATA syntax (if you used that command). But the code below works as well. The leading zero of single-digit days are missing, which makes it a bit more difficult. Cheers!! Albert-Jan data list free / old (a15). begin data '10/13/1987 0:00' '7/23/1991 0:00' '12/11/1954 0:00' end data. compute #slash1 = index(old, "/"). compute #slash2 = rindex(old, "/"). compute new = date.mdy( number(substr(old, 1, #slash1-1), n2), number(substr(old, #slash1+1, #slash2-1), n2), number(substr(old, #slash2+1, 4), n4)). formats new (adate12). --- On Fri, 2/27/09, David Wright <[hidden email]> wrote: > From: David Wright <[hidden email]> > Subject: remove trailing alphas from var length string > To: [hidden email] > Date: Friday, February 27, 2009, 1:08 PM > I have a date variable which is imbedded in a string (length > is A15) > shown below. I need to either extract the date or remove > the trailing " > 0:00" to convert the left portion into a date. Any > suggestions greatly > welcomed, thanks > > > 10/13/1987 0:00 > 7/23/1991 0:00 > 12/11/1954 0:00 > > > David > > ===================== > 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 |
Is he cheating on me? Find Out on Yahoo Answers |
|
Administrator
|
>I am using compute command to generate additional >variables. For illustration purposes, suppose I have >six variables X1, X2, Y1, Y2, Z1, Z2. Then I would >compute more variables with the following syntax:
>COMPUTE X=max(X1,X2)-min(X1,Xf2). >EXECUTE. >COMPUTE Y=max(Y1,Y2)-min(Y1,Y2). >EXECUTE. >COMPUTE Z=max(Z1,Z2)-min(Z1,Z2). >EXECUTE. >Compute W= X/sum(X to Z)*100. >EXECUTE. >Compute Q= Y/sum(X to Z)*100. >EXECUTE. >Compute R= Z/sum(X to Z)*100. >EXECUTE. >Now, computing six additional variables from the >given six would take 12-line syntax. Thus,it needs >200-line syntax for 100 variables..and generally 2p >lines for p variables. >Can someone modify the syntax to make it shorter >and generic(any number of variables)? 1. Get rid of the EXECUTE commands. They are unnecessary and very inefficient 2. Look in the Help/Manual for DO REPEAT command. eg: DO REPEAT OUT=X Y Z / IN1=X1 Y1 Z1 / IN2=X2 Y2 Z2. COMPUTE OUT = MAX(IN1,IN2)-MIN(IN1,IN2). END REPEAT. I leave the rest for you to fill in! BTW, It is unnecessary to compute the denominator 3 times in the second set of computations ;-) HTH, David Marso
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?" |
| Free forum by Nabble | Edit this page |
