Problem with macro

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

Problem with macro

88videos
Hi, thanks in advance for you help.

I 've got problem with macro. I don't how to automate same transformations.

Simple example

I want to have 50 bases with 1000 cases and only 2 variables:
id
z1 - random value from uniform distribution, min=1, max=100.


I wrote this macro

DEFINE macro1 (arg1=!TOKENS(1))

INPUT PROGRAM.
loop #i=1 to 1000.
compute id=#i.
compute z1=RV.UNIFORM(1, 100).
end case.
end loop.
end file.
END INPUT PROGRAM.
EXECUTE.
dataset name !arg1.

!enddefine.

To get what i wanted I must write next 50 lines!

macro1 base1
macro1 base2
.....
macro1 base50

But I am sure there is other solution....

How should I modify my macro to automate this process?














Wolny od wirusów. www.avast.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: Problem with macro

Rich Ulrich

I can't solve your Macro/naming problem. But creating 50 separate datasets with
50 separate names leaves you with the further problem of dealing with those
50 names one at a time when it comes to analyses.

The usual procedure for 50 randomizations is to create a counter from 1 to 50
and process the one file using Split File.

--
Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of 88Videoclips . <[hidden email]>
Sent: Sunday, April 2, 2017 2:23:06 PM
To: [hidden email]
Subject: Problem with macro
 
Hi, thanks in advance for you help.

I 've got problem with macro. I don't how to automate same transformations.

Simple example

I want to have 50 bases with 1000 cases and only 2 variables:
id
z1 - random value from uniform distribution, min=1, max=100.


I wrote this macro

DEFINE macro1 (arg1=!TOKENS(1))

INPUT PROGRAM.
loop #i=1 to 1000.
compute id=#i.
compute z1=RV.UNIFORM(1, 100).
end case.
end loop.
end file.
END INPUT PROGRAM.
EXECUTE.
dataset name !arg1.

!enddefine.

To get what i wanted I must write next 50 lines!

macro1 base1
macro1 base2
.....
macro1 base50

But I am sure there is other solution....

How should I modify my macro to automate this process?














Wolny od wirusów. www.avast.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: Problem with macro

Jon Peck
As Rich said, you will wind up with 50 different open datasets, which are not saved.  Is that really what you want?

Easy to do, though, with a small amount of Python code, which is simpler than wading through macro..

begin program.
import spss
for i in range(3):
    spss.Submit(r"""INPUT PROGRAM.
loop #i=1 to 1000.
compute id=#i.
compute z1=RV.UNIFORM(1, 100).
end case.
end loop.
end file.
END INPUT PROGRAM.
dataset name base%s.""" %i)
end program.


On Mon, Apr 3, 2017 at 10:19 AM, Rich Ulrich <[hidden email]> wrote:

I can't solve your Macro/naming problem. But creating 50 separate datasets with
50 separate names leaves you with the further problem of dealing with those
50 names one at a time when it comes to analyses.

The usual procedure for 50 randomizations is to create a counter from 1 to 50
and process the one file using Split File.

--
Rich Ulrich


From: SPSSX(r) Discussion <[hidden email]> on behalf of 88Videoclips . <[hidden email]>
Sent: Sunday, April 2, 2017 2:23:06 PM
To: [hidden email]
Subject: Problem with macro
 
Hi, thanks in advance for you help.

I 've got problem with macro. I don't how to automate same transformations.

Simple example

I want to have 50 bases with 1000 cases and only 2 variables:
id
z1 - random value from uniform distribution, min=1, max=100.


I wrote this macro

DEFINE macro1 (arg1=!TOKENS(1))

INPUT PROGRAM.
loop #i=1 to 1000.
compute id=#i.
compute z1=RV.UNIFORM(1, 100).
end case.
end loop.
end file.
END INPUT PROGRAM.
EXECUTE.
dataset name !arg1.

!enddefine.

To get what i wanted I must write next 50 lines!

macro1 base1
macro1 base2
.....
macro1 base50

But I am sure there is other solution....

How should I modify my macro to automate this process?














Wolny od wirusów. www.avast.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



--
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: Problem with macro

Rich Ulrich
In reply to this post by 88videos

Concerning
compute z1=RV.UNIFORM(1, 100).

- You probably want something different from this continuous range. 

From https://www.spss-tutorials.com/spss-rv-function/

RV.UNIFORM(mininum,maximum)
draws values from a (continuous) uniform distribution.
This means that all values have the same chance of occurring.

An example are throws with a balanced die: values 1 through 6 all have the same chance of (1/6) of occurring.
This can be simulated by TRUNC(RV.UNIFORM(1,7)).
The fractional values are discretized here by truncating them.


--

Rich Ulrich




===================== 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: Problem with macro

David Marso
Administrator
In reply to this post by 88videos
As others have stated.  I doubt that you will want to have 50 datasets.  Maybe lookup SPLIT FILE.
What is the intention of this exercise?
--

Maybe try the following approach:

DEFINE !MakeData (NRows !TOKENS(1) / NSamples  !TOKENS(1))
MATRIX.
LOOP ID=1 TO NSamples.
SAVE ({MAKE(!NRows,1,ID),UNIFORM(!NRows,1)}) / OUTFILE * / VARIABLES ID Uniform01 .
END LOOP.
END MATRIX.
!ENDDEFINE.

DATASET NAME simulated.
SPLIT FILE BY ID .
DESCRIPTIVES Uniform01 .



88videos wrote
Hi, thanks in advance for you help.

I 've got problem with macro. I don't how to automate same transformations.

Simple example

I want to have 50 bases with 1000 cases and only 2 variables:
id
z1 - random value from uniform distribution, min=1, max=100.


I wrote this macro

DEFINE macro1 (arg1=!TOKENS(1))

INPUT PROGRAM.
loop #i=1 to 1000.
compute id=#i.
compute z1=RV.UNIFORM(1, 100).
end case.
end loop.
end file.
END INPUT PROGRAM.
EXECUTE.
dataset name !arg1.

!enddefine.

To get what i wanted* I must write next 50 lines!*

macro1 base1
macro1 base2
.....
macro1 base50

But I am sure there is other solution....

How should I modify my macro to automate this process?














<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Wolny
od wirusów. www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

=====================
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: Problem with macro

88videos
In reply to this post by Rich Ulrich
First I want to thank all of you.

In example I tried to show something.


@Rich Ulrich
I know that ruounding is necessary.

I know that in case i described I should work on 1 base and use splite file procedure.
This is immaginary example, I try to learn about using other than number arguments in macro and automation of this procces.



@David Marso
"What is the intension of this exercise?"

I want to learn how to avoid writing 50 times execution of some macro e.g. macro1 base1, macro1 base2 ..
I do this, when in argumentI I have numbers, but have problem with string argument.

Easy example with number agument.
I want to build 5  AR models: ARIMA (1, 0, 0) ARIMA (2, 0, 0) ARIMA (3, 0, 0) ARIMA (4, 0, 0) ARIMA (5, 0, 0)


*1) to generate data for example

input program.
loop #i=1 to 250.
compute id=#i.
end case.
end loop.
end file.
end input program.
execute.

compute z1=RV.UNIFORM(0, 1).
execute.


*2) writing a macro

*2.1) macro without loop inside

Define macro2 (arg1=!TOKENS(1))
use thru 240.
PREDICT THRU 250.
TSMODEL
   /MODELSUMMARY  PRINT=[MODELFIT]
   /MODELSTATISTICS  DISPLAY=YES MODELFIT=[ SRSQUARE]
   /SERIESPLOT OBSERVED FORECAST
   /OUTPUTFILTER DISPLAY=ALLMODELS
   /AUXILIARY  CILEVEL=95 MAXACFLAGS=24
   /MISSING USERMISSING=EXCLUDE
   /MODEL DEPENDENT=z1
      PREFIX='Model'
   /ARIMA AR=[!arg1] DIFF=0 MA=[0]
      ARSEASONAL=[0]  DIFFSEASONAL=0  MASEASONAL=[0]
      TRANSFORM=NONE CONSTANT=YES
   /AUTOOUTLIER DETECT=OFF.
!enddefine.

*2.2) macro with loop inside

Define macro3 (arg1=!TOKENS(1))
!DO !k=1 !TO !arg1.
use thru 240.
PREDICT THRU 250.
TSMODEL
   /MODELSUMMARY  PRINT=[MODELFIT]
   /MODELSTATISTICS  DISPLAY=YES MODELFIT=[ SRSQUARE]
   /SERIESPLOT OBSERVED FORECAST
   /OUTPUTFILTER DISPLAY=ALLMODELS
   /AUXILIARY  CILEVEL=95 MAXACFLAGS=24
   /MISSING USERMISSING=EXCLUDE
   /MODEL DEPENDENT=z1
      PREFIX='Model'
   /ARIMA AR=[!k] DIFF=0 MA=[0]
      ARSEASONAL=[0]  DIFFSEASONAL=0  MASEASONAL=[0]
      TRANSFORM=NONE CONSTANT=YES
   /AUTOOUTLIER DETECT=OFF.
!DOEND
!enddefine.


*3) execution of macro

*3.1.) macro without loop inside
macro2 arg1=1
macro2 arg1=2
macro2 arg1=3
macro2 arg1=4
macro2 arg1=5

*3.2.) macro with loop inside

macro3 arg1=5


To sum up. In second solution 1 line, in first 5 lines. I am not sure, but something tells me that similar automation is possible in my 1 example.

???



David, I have to admit that i don' t understand all elements of your syntax commands.

"Save ({make" is new for me.
Is your syntax is all I need to execute?
When I copy/paste/execute it I got error.
Maybe I should have made changes in your commands? But without understanding this part save/make i don't know how...

Other questions
1) Why you use space instead of "=" to define arguments? That new for me too.
2) In your command I can't see line with execution , "!makeData ....". Why?

Thanks for answears.



@Jon Peck
Thanks, but I try to learn how to solve some problems without programming tricks :)






2017-04-03 19:28 GMT+02:00 Rich Ulrich <[hidden email]>:

Concerning
compute z1=RV.UNIFORM(1, 100).

- You probably want something different from this continuous range. 

From https://www.spss-tutorials.com/spss-rv-function/

RV.UNIFORM(mininum,maximum)
draws values from a (continuous) uniform distribution.
This means that all values have the same chance of occurring.

An example are throws with a balanced die: values 1 through 6 all have the same chance of (1/6) of occurring.
This can be simulated by TRUNC(RV.UNIFORM(1,7)).
The fractional values are discretized here by truncating them.


--

Rich Ulrich





===================== 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: Problem with macro

Rich Ulrich

re:

   " @Rich Ulrich
     I know that ruounding is necessary."

Rounding is only half the problem, which truncating makes more evident:


Taking Uniform from 1 to 100 gives a range of 99, with 1/99 being the

probability for most integers.  Trunc( )  would mean that you would

never see 100;  Round( ) would mean that you would see 1 and 100 with

only a 50% chance of 1/99 for each, a fault that would be harder to notice.


--

Rich Ulrich

 
===================== 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: Problem with macro

88videos
@ Rich Ulrich

Good point.

To be correct in case I described I should have used "trunc" instead of "rnd". This is important detail. You are right. Thanks.



Wolny od wirusów. www.avast.com

2017-04-08 19:08 GMT+02:00 Rich Ulrich <[hidden email]>:

re:

   " @Rich Ulrich
     I know that ruounding is necessary."

Rounding is only half the problem, which truncating makes more evident:


Taking Uniform from 1 to 100 gives a range of 99, with 1/99 being the

probability for most integers.  Trunc( )  would mean that you would

never see 100;  Round( ) would mean that you would see 1 and 100 with

only a 50% chance of 1/99 for each, a fault that would be harder to notice.


--

Rich Ulrich

 

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