Use current data to create new records

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

Use current data to create new records

Kevin Bladon
Hello all,

Does anyone know how to copy the entire contents of several records except
for one field?  For example, if I start with the following data:

id      spec    area    year    tpr
975 SB 22.84 2003 M
975 SW .01 2003 F
975 AW 68.17 2008 M

I would like to create an output file using the above data that would look
something like this:

id      spec    area    year    tpr
975 SB 22.84 2003 M
975 SB 22.84 2004 M
975 SB 22.84 2005 M
975 SB 22.84 2006 M
975 SB 22.84 2007 M
975 SW .01 2003 F
975 SW .01 2004 F
975 SW .01 2005 F
975 SW .01 2006 F
975 SW .01 2007 F
975 AW 68.17 2008 M
975 AW 68.17 2009 M
975 AW 68.17 2010 M
975 AW 68.17 2011 M
975 AW 68.17 2012 M

In other words I have a data set with a year column which represents the
first year in a 5 year sequence.  However, I need to create a record for
each year in the 5 year sequence as an input into an external model.

Hope this is clear and that someone knows how this may be done.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Use current data to create new records

Roberts, Michael
Hi,

Can you clarify further?  Are you trying to populate the year field
while keeping the 'id', 'spec' and 'tpr' values the same?


Mike


-----Original Message-----
From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of
Kevin Bladon
Sent: Wednesday, June 20, 2007 3:57 PM
To: [hidden email]
Subject: Use current data to create new records

Hello all,

Does anyone know how to copy the entire contents of several records
except for one field?  For example, if I start with the following data:

id      spec    area    year    tpr
975 SB 22.84 2003 M
975 SW .01 2003 F
975 AW 68.17 2008 M

I would like to create an output file using the above data that would
look something like this:

id      spec    area    year    tpr
975 SB 22.84 2003 M
975 SB 22.84 2004 M
975 SB 22.84 2005 M
975 SB 22.84 2006 M
975 SB 22.84 2007 M
975 SW .01 2003 F
975 SW .01 2004 F
975 SW .01 2005 F
975 SW .01 2006 F
975 SW .01 2007 F
975 AW 68.17 2008 M
975 AW 68.17 2009 M
975 AW 68.17 2010 M
975 AW 68.17 2011 M
975 AW 68.17 2012 M

In other words I have a data set with a year column which represents the
first year in a 5 year sequence.  However, I need to create a record for
each year in the 5 year sequence as an input into an external model.

Hope this is clear and that someone knows how this may be done.

Thanks!
Reply | Threaded
Open this post in threaded view
|

Re: Use current data to create new records

Kevin Bladon
In reply to this post by Kevin Bladon
Essentially, yes.  The year field already is completed for one record.  I
would want to duplicate that record 4 other times keeping all values the
same except for the year field.  The year field in the new records would
then be populated sequentially from the first year by adding one year to
each new record.

I would need to do this for every record in my current data.

Thanks.
Reply | Threaded
Open this post in threaded view
|

Re: Use current data to create new records

Richard Ristow
In reply to this post by Kevin Bladon
At 03:57 PM 6/20/2007, Kevin Bladon wrote:

>Does anyone know how to copy the entire contents of several records
>except for one field?  For example, if I start with the following data:
>
>id      spec    area    year    tpr
>975 SB 22.84 2003 M
>975 SW .01 2003 F
>975 AW 68.17 2008 M
>
>I would like to create an output file [with] a record for each year in
>the 5 year sequence [beginning with the observed year].


XSAVE is your friend, here. This is SPSS 15 draft output. The "Warning
# 142" regarding XSAVE is a known bug in SPSS 15; it means nothing.
|-----------------------------|---------------------------|
|Output Created               |20-JUN-2007 19:17:09       |
|-----------------------------|---------------------------|
   id spec    area year tpr

  975 SB     22.84 2003 M
  975 SW       .01 2003 F
  975 AW     68.17 2008 M

Number of cases read:  3    Number of cases listed:  3


NUMERIC StartYr  (F4).
STRING  ComeFrom (A6).
COMPUTE StartYr = year.

LOOP year = StartYr TO StartYr + 4.
.  COMPUTE    ComeFrom = '?????'.
.  DO IF year EQ StartYr.
.     COMPUTE ComeFrom = 'Real'.
.  ELSE.
.     COMPUTE ComeFrom = 'Create'.
.  END IF.
.  XSAVE OUTFILE=Expand

 >Warning # 142.  Command name: XSAVE
 >LOOP has no effect on this command.

       /DROP = StartYr.
END LOOP.
EXECUTE  /* which is necessary, here */.

GET FILE=Expand.
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |20-JUN-2007 19:17:10       |
|-----------------------------|---------------------------|
C:\Documents and Settings\Richard\My Documents\Temporary\SPSS
   \2007-06-20 Bladon - Use current data to create new records.SAV

   id spec    area year tpr ComeFrom

  975 SB     22.84 2003 M   Real
  975 SB     22.84 2004 M   Create
  975 SB     22.84 2005 M   Create
  975 SB     22.84 2006 M   Create
  975 SB     22.84 2007 M   Create
  975 SW       .01 2003 F   Real
  975 SW       .01 2004 F   Create
  975 SW       .01 2005 F   Create
  975 SW       .01 2006 F   Create
  975 SW       .01 2007 F   Create
  975 AW     68.17 2008 M   Real
  975 AW     68.17 2009 M   Create
  975 AW     68.17 2010 M   Create
  975 AW     68.17 2011 M   Create
  975 AW     68.17 2012 M   Create

Number of cases read:  15    Number of cases listed:  15
=================================
APPENDIX: Test data & file handle
=================================

*  ................................................................. .
*  .................   Test data and FILE HANDLE   ................. .

FILE HANDLE Expand
   /NAME='C:\Documents and Settings\Richard\My Documents'             +
           '\Temporary\SPSS\'                                         +
         '2007-06-20 Bladon - Use current data to create new records' +
         '.SAV'.

DATA LIST LIST SKIP=1/
    id      spec    area    year    tpr
   (F4,     A2,     F6.2    F4      A1).
BEGIN DATA
    id      spec    area    year    tpr
    975 SB 22.84 2003 M
    975 SW .01 2003 F
    975 AW 68.17 2008 M
END DATA.
*  .................   Post after this point   ..................... .
*  ................................................................. .
LIST.
Reply | Threaded
Open this post in threaded view
|

Re: Use current data to create new records

Kevin Bladon
Richard,

Fantastic!  Great skills.  That worked very nicely for me.

Thanks.
Kevin.

-----Original Message-----
From: Richard Ristow [mailto:[hidden email]]
Sent: June 20, 2007 17:23
To: Kevin Bladon; [hidden email]
Subject: Re: Use current data to create new records

At 03:57 PM 6/20/2007, Kevin Bladon wrote:

>Does anyone know how to copy the entire contents of several records
>except for one field?  For example, if I start with the following data:
>
>id      spec    area    year    tpr
>975 SB 22.84 2003 M
>975 SW .01 2003 F
>975 AW 68.17 2008 M
>
>I would like to create an output file [with] a record for each year in
>the 5 year sequence [beginning with the observed year].


XSAVE is your friend, here. This is SPSS 15 draft output. The "Warning
# 142" regarding XSAVE is a known bug in SPSS 15; it means nothing.
|-----------------------------|---------------------------|
|Output Created               |20-JUN-2007 19:17:09       |
|-----------------------------|---------------------------|
   id spec    area year tpr

  975 SB     22.84 2003 M
  975 SW       .01 2003 F
  975 AW     68.17 2008 M

Number of cases read:  3    Number of cases listed:  3


NUMERIC StartYr  (F4).
STRING  ComeFrom (A6).
COMPUTE StartYr = year.

LOOP year = StartYr TO StartYr + 4.
.  COMPUTE    ComeFrom = '?????'.
.  DO IF year EQ StartYr.
.     COMPUTE ComeFrom = 'Real'.
.  ELSE.
.     COMPUTE ComeFrom = 'Create'.
.  END IF.
.  XSAVE OUTFILE=Expand

 >Warning # 142.  Command name: XSAVE
 >LOOP has no effect on this command.

       /DROP = StartYr.
END LOOP.
EXECUTE  /* which is necessary, here */.

GET FILE=Expand.
LIST.

List
|-----------------------------|---------------------------|
|Output Created               |20-JUN-2007 19:17:10       |
|-----------------------------|---------------------------|
C:\Documents and Settings\Richard\My Documents\Temporary\SPSS
   \2007-06-20 Bladon - Use current data to create new records.SAV

   id spec    area year tpr ComeFrom

  975 SB     22.84 2003 M   Real
  975 SB     22.84 2004 M   Create
  975 SB     22.84 2005 M   Create
  975 SB     22.84 2006 M   Create
  975 SB     22.84 2007 M   Create
  975 SW       .01 2003 F   Real
  975 SW       .01 2004 F   Create
  975 SW       .01 2005 F   Create
  975 SW       .01 2006 F   Create
  975 SW       .01 2007 F   Create
  975 AW     68.17 2008 M   Real
  975 AW     68.17 2009 M   Create
  975 AW     68.17 2010 M   Create
  975 AW     68.17 2011 M   Create
  975 AW     68.17 2012 M   Create

Number of cases read:  15    Number of cases listed:  15
=================================
APPENDIX: Test data & file handle
=================================

*  ................................................................. .
*  .................   Test data and FILE HANDLE   ................. .

FILE HANDLE Expand
   /NAME='C:\Documents and Settings\Richard\My Documents'             +
           '\Temporary\SPSS\'                                         +
         '2007-06-20 Bladon - Use current data to create new records' +
         '.SAV'.

DATA LIST LIST SKIP=1/
    id      spec    area    year    tpr
   (F4,     A2,     F6.2    F4      A1).
BEGIN DATA
    id      spec    area    year    tpr
    975 SB 22.84 2003 M
    975 SW .01 2003 F
    975 AW 68.17 2008 M
END DATA.
*  .................   Post after this point   ..................... .
*  ................................................................. .
LIST.