Regular sequnces and data

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

Regular sequnces and data

Robert L

Is there any quick way to set up a dataset where some of the variables are regular sequences such as year and month? If I use the following loop:

 

NEW FILE.
INPUT PROGRAM.
LOOP year=1 TO 2.
LEAVE year.
LOOP month=1 to 12.
END CASE.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.

DATASET NAME fake_data.

 

then I will get the beginning, the year and month variables. But what if I want to add some variable? Setting up a new dataset with DATA LIST... is possible, followed by a MATCH FILES operation. But it would be handy to add a new simple variable by hand within the same dataset as the year and month variables, such as using "data<-c()" in R. Possible or not?

===================== 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
Reply | Threaded
Open this post in threaded view
|

Re: Regular sequnces and data

Maguin, Eugene

What’s wrong with

Compute ww=27.

 

Or

Define a new variable name in the data window and key in whatever values you want.

 

Gene Maguin

 

From: SPSSX(r) Discussion <[hidden email]> On Behalf Of Robert Lundqvist
Sent: Thursday, July 12, 2018 8:10 AM
To: [hidden email]
Subject: Regular sequnces and data

 

Is there any quick way to set up a dataset where some of the variables are regular sequences such as year and month? If I use the following loop:

 

NEW FILE.
INPUT PROGRAM.
LOOP year=1 TO 2.
LEAVE year.
LOOP month=1 to 12.
END CASE.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.

DATASET NAME fake_data.

 

then I will get the beginning, the year and month variables. But what if I want to add some variable? Setting up a new dataset with DATA LIST... is possible, followed by a MATCH FILES operation. But it would be handy to add a new simple variable by hand within the same dataset as the year and month variables, such as using "data<-c()" in R. Possible or not?

===================== 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: Regular sequnces and data

David Marso
Administrator
In reply to this post by Robert L
Robert,
I noticed you posted this under an entirely unrelated thread.  Please don't
do that!
I had to manually move it.

Answer: ditch the INPUT PROGRAM and just use some LAGs within a DO IF
structure.

IF ($CASENUM EQ 1) year = 1.
COMPUTE month= SUM(LAG(month),1).
DO IF (month EQ 13).
+  COMPUTE year=SUM(LAG(year), 1).
+  COMPUTE month= 1.
END IF.


Robert L wrote

> Is there any quick way to set up a dataset where some of the variables are
> regular sequences such as year and month? If I use the following loop:
>
>
>
> NEW FILE.
> INPUT PROGRAM.
> LOOP year=1 TO 2.
> LEAVE year.
> LOOP month=1 to 12.
> END CASE.
> END LOOP.
> END LOOP.
> END FILE.
> END INPUT PROGRAM.
>
> DATASET NAME fake_data.
>
>
>
> then I will get the beginning, the year and month variables. But what if I
> want to add some variable? Setting up a new dataset with DATA LIST... is
> possible, followed by a MATCH FILES operation. But it would be handy to
> add a new simple variable by hand within the same dataset as the year and
> month variables, such as using "data<-c()" in R. Possible or not?
>
> =====================
> 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





-----
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?"
--
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
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: Regular sequnces and data

David Marso
Administrator
Even easier but a little less readable/grokable?

COMPUTE month= SUM(LAG(month),1).
IF (month EQ 13) month= 1.
COMPUTE year=SUM(LAG(year), (month EQ 1) ).




-----
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?"
--
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
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: Regular sequnces and data

Jon Peck
The question was about how to add a variable with an arbitrary sequence of variables.  Data list and match is the only native way other than manual entry in the DE.  You could actually use the R code you showed, but the code to define and match this into the active dataset would be more involved than the simple data list/match.

On Thu, Jul 12, 2018 at 7:04 AM David Marso <[hidden email]> wrote:
Even easier but a little less readable/grokable?

COMPUTE month= SUM(LAG(month),1).
IF (month EQ 13) month= 1.
COMPUTE year=SUM(LAG(year), (month EQ 1) ).




-----
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?"
--
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
--
Jon K Peck
[hidden email]

===================== 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: Regular sequnces and data

Rich Ulrich
In reply to this post by Robert L

As I read this, you do know how to create 24 records for two years, identified

by year and month. You want to add variables that have a known year and month.


UPDATE is the command that allows you to do that. If the transaction file has a variable

which is in the master file, the value from the transaction file replaces it. If the variable is

new to the master file, the variable is added to the file. You should save your sets of UPDATE

runs for documentation and for the possibility that you might want to re-do it all.


--

Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of Robert Lundqvist <[hidden email]>
Sent: Thursday, July 12, 2018 8:10:10 AM
To: [hidden email]
Subject: Regular sequnces and data
 

Is there any quick way to set up a dataset where some of the variables are regular sequences such as year and month? If I use the following loop:

 

NEW FILE.
INPUT PROGRAM.
LOOP year=1 TO 2.
LEAVE year.
LOOP month=1 to 12.
END CASE.
END LOOP.
END LOOP.
END FILE.
END INPUT PROGRAM.

DATASET NAME fake_data.

 

then I will get the beginning, the year and month variables. But what if I want to add some variable? Setting up a new dataset with DATA LIST... is possible, followed by a MATCH FILES operation. But it would be handy to add a new simple variable by hand within the same dataset as the year and month variables, such as using "data<-c()" in R. Possible or not?

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