MACRO

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

MACRO

Deepanshu Bhalla
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: MACRO

Bruce Weaver
Administrator
You need to provide more information.  Are the 50 files named in some systematic way (e.g., File1.sav, File2.sav, ... File50.sav)?  If not, you'll probably have to hand the file names to the macro as a list of arguments.  (The old DOS command DIR can be used to generate a text file containing the file names.  The command would be something like:  dir /b > filelist.txt )  

Re your computation of ISENG, you could replace
 
IF eng >=4 iseng =1.
IF eng<4 iseng =0.

with

COMPUTE iseng = (eng GE 4).

HTH.


deepanshu bhalla wrote
Hi Team,

I have multiple sav formatted files in the folder and one template that contains all the variables that the multiple files have .

Right now i manually open each file use ADD FILES to combine cases and do some compute commands and then save the file by the name it was earlier.

It is very tedious process as i have more than 50 files and i have to do the same task in all of them ..

I am looking for some cool macro that open template file and use ADD FILES to combine cases into the template and do some computing stuff and close the file after saving it ...
Assume all the files are stored in one folder.

My syntax looks like this :

GET FILE = " TEMPLATE FILE PATH".

ADD FILES FILE =*
/ FILE = "PATH".

Compute eng = mean (Q1,Q2,Q3,Q4).
IF eng >=4 iseng =1.
IF eng<4 iseng =0.
execute.

SAVE OUTFILE ="PATH".


Thanks in advance !
--
Bruce Weaver
bweaver@lakeheadu.ca
http://sites.google.com/a/lakeheadu.ca/bweaver/

"When all else fails, RTFM."

PLEASE NOTE THE FOLLOWING: 
1. My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above.
2. The SPSSX Discussion forum on Nabble is no longer linked to the SPSSX-L listserv administered by UGA (https://listserv.uga.edu/).
Reply | Threaded
Open this post in threaded view
|

Re: MACRO

David Marso
Administrator
In reply to this post by Deepanshu Bhalla
For MACRO look up DEFINE !ENDDEFINE in the manual.
To iterate over lists see !DO !DOEND
To glue stuff together see !CONCAT
!QUOTE may also be useful.
eg
DEFINE DoIt (Start !TOKENS(1) / End !TOKENS(1) )
!DO !F=!Start !TO !End
!LET !QtPlusF=!QUOTE(!CONCAT ("Plus",!F))
---do stuff with !QtPlusF---
!DOEND
!ENDDEFINE.
Doit Start=1 End=50.

DEFINE DoIt2 (MyList !CharEnd("/")  )
!DO !F !IN (!MyList)
!LET !QtPlusF=!QUOTE(!CONCAT ("Plus",!F))
---do stuff with !QtPlusF---
!DOEND
!ENDDEFINE.
DoIt2 MyList a b c d e f .

These are the general essentials.  Will leave you to puzzle out the specifics.
HTH, David

deepanshu bhalla wrote
Hi Team,

I have multiple sav formatted files in the folder and one template that contains all the variables that the multiple files have .

Right now i manually open each file use ADD FILES to combine cases and do some compute commands and then save the file by the name it was earlier.

It is very tedious process as i have more than 50 files and i have to do the same task in all of them ..

I am looking for some cool macro that open template file and use ADD FILES to combine cases into the template and do some computing stuff and close the file after saving it ...
Assume all the files are stored in one folder.

My syntax looks like this :

GET FILE = " TEMPLATE FILE PATH".

ADD FILES FILE =*
/ FILE = "PATH".

Compute eng = mean (Q1,Q2,Q3,Q4).
IF eng >=4 iseng =1.
IF eng<4 iseng =0.
execute.

SAVE OUTFILE ="PATH".


Thanks in advance !
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: MACRO

Jon K Peck
In reply to this post by Deepanshu Bhalla
This would be easy to do using a little Python programmability to determine what files are in some specified directory based, perhaps, on a wild card name and run through the merge steps.

If you are not up to writing the Python code, you could use the SPSSINC PROCESS FILES extension command to do this.  That would be a little less efficient, since it would do the merges one file at a time, but that might not matter unless the data files are quite large, and it would eliminate the need for you to write and maintain any Python code.

You can get this command and the Python Essentials prerequisite from the SPSS Community website (www.ibm.com/developerworks/spssdevcentral).

Jon Peck (no "h") aka Kim
Senior Software Engineer, IBM
[hidden email]
new phone: 720-342-5621




From:        deepanshu bhalla <[hidden email]>
To:        [hidden email]
Date:        03/01/2012 07:42 AM
Subject:        [SPSSX-L] MACRO
Sent by:        "SPSSX(r) Discussion" <[hidden email]>




Hi Team,

I have multiple sav formatted files in the folder and one template that contains all the variables that the multiple files have .

Right now i manually open each file use ADD FILES to combine cases and do some compute commands and then save the file by the name it was earlier.

It is very tedious process as i have more than 50 files and i have to do the same task in all of them ..

I am looking for some cool macro that open template file and use ADD FILES to combine cases into the template and do some computing stuff and close the file after saving it ...
Assume all the files are stored in one folder.

My syntax looks like this :

GET FILE = " TEMPLATE FILE PATH".

ADD FILES FILE =*
/ FILE = "PATH".

Compute eng = mean (Q1,Q2,Q3,Q4).
IF eng >=4 iseng =1.
IF eng<4 iseng =0.
execute.

SAVE OUTFILE ="PATH".


Thanks in advance !



Reply | Threaded
Open this post in threaded view
|

Re: MACRO

Albert-Jan Roskam
In reply to this post by Deepanshu Bhalla
Hi,

Did you consider using APPLY DICTIONARY for the template file?

I just cobbled together some code that generates the ADD FILES commands. I always forget the add files maximum though, I believe it's around 50 files.
The code runs, but I don't have spss on this machine.

import os, glob
import spss
path = "/home/aj/Desktop/blah"
template = os.path.join(path, "sometemplate.sav")
addfiles = "add files / file = '%s'" % template
files = glob.glob(os.path.join(path, "*.sav"))
nfiles = len(files)
for i, f in enumerate(sorted(files)):
    addfiles += "\n\t/file = '%s'" % f
    nfiles -= 1
    if i % 50 == 0 and i > 0: # is 50 the add files limit?
        addfiles += ".\nexe."
        if nfiles != 0:
            addfiles += "\nadd files /file = * "
#print addfiles
spss.Submit(addfiles)
 
Regards,
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

From: deepanshu bhalla <[hidden email]>
To: [hidden email]
Sent: Thursday, March 1, 2012 3:32 PM
Subject: [SPSSX-L] MACRO

Hi Team,

I have multiple sav formatted files in the folder and one template that contains all the variables that the multiple files have .

Right now i manually open each file use ADD FILES to combine cases and do some compute commands and then save the file by the name it was earlier.

It is very tedious process as i have more than 50 files and i have to do the same task in all of them ..

I am looking for some cool macro that open template file and use ADD FILES to combine cases into the template and do some computing stuff and close the file after saving it ...
Assume all the files are stored in one folder.

My syntax looks like this :

GET FILE = " TEMPLATE FILE PATH".

ADD FILES FILE =*
/ FILE = "PATH".

Compute eng = mean (Q1,Q2,Q3,Q4).
IF eng >=4 iseng =1.
IF eng<4 iseng =0.
execute.

SAVE OUTFILE ="PATH".


Thanks in advance !





Reply | Threaded
Open this post in threaded view
|

Re: MACRO

Albert-Jan Roskam
In reply to this post by Deepanshu Bhalla
addendum to my previous mail: It would be handy to have a Python extension command that not only doesn't have the default ADD FILES max number of files limit, but also doesn't have the 'different string length' nuisance (comparable to SAS's 'force append'). To make it become totally nerdy, it should also be able to add little- and bigendian files (which I believe is not possible with ADD FILES).;-)

I might make it, and will let you know when it's finished.
 
Regards,
Albert-Jan

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public order, irrigation, roads, a
fresh water system, and public health, what have the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 

From: deepanshu bhalla <[hidden email]>
To: [hidden email]
Sent: Thursday, March 1, 2012 3:32 PM
Subject: [SPSSX-L] MACRO

Hi Team,

I have multiple sav formatted files in the folder and one template that contains all the variables that the multiple files have .

Right now i manually open each file use ADD FILES to combine cases and do some compute commands and then save the file by the name it was earlier.

It is very tedious process as i have more than 50 files and i have to do the same task in all of them ..

I am looking for some cool macro that open template file and use ADD FILES to combine cases into the template and do some computing stuff and close the file after saving it ...
Assume all the files are stored in one folder.

My syntax looks like this :

GET FILE = " TEMPLATE FILE PATH".

ADD FILES FILE =*
/ FILE = "PATH".

Compute eng = mean (Q1,Q2,Q3,Q4).
IF eng >=4 iseng =1.
IF eng<4 iseng =0.
execute.

SAVE OUTFILE ="PATH".


Thanks in advance !