Hi all! I hope somewhat might have a suggestion, because this sure has
been taking me a while. What I'm trying to do: build a macro that takes a text file, brings it into spss, computes a new variable based on the id number of the file, and spits out an spss file. However, the input filenames are not standardized so I made them into macros, thinking that I could use a string concatenate function to bring in the files. The problem: The macro works fine if I type in a generic filename in the fourth line of the long macro (for the get data file name). It will go through the loop and save as separate outfiles. However, when I try to use the concat function to recognize the macros, it won't work. Does anyone have any ideas of how to get this to work or restructure the code so it will work? Someone suggested perhaps creating a separate file with the filepaths and subject numbers in it, and making it into a vector? I am not sure how to go about doing this, and I wanted to make sure that there was no hope left for my current code first. Any suggestions would be superfabulous! Code follows: ***MACROS for filepath and filenames. DEFINE !IV01path () < really long filepath> !ENDDEFINE. DEFINE !IV01outpath () <filepath> !ENDDEFINE. DEFINE !IV01nameS1001 () <ridiculously long unstandardized filenaming convention> !ENDDEFINE. DEFINE !IV01nameS1002 ()<ridiculously long unstandardized filenaming convention> !ENDDEFINE. DEFINE !IV01nameS1003 ()<ridiculously long unstandardized filenaming convention> !ENDDEFINE. DEFINE !GETFILE (). !DO !I = 1001 !TO 1020. GET DATA /TYPE = TXT /FILE = !IV01path + !CONCAT('!IV01nameS' !I) /DELCASE = LINE /DELIMITERS = "\t" /ARRANGEMENT = DELIMITED /FIRSTCASE = 2 /IMPORTCASE = ALL /VARIABLES = Var1 F2.0 Var2 A2 Var3 F5.0 Var4 A1 Var5 F5.0 Var6 A1 Var7 A2 Var8 F5.0 Var9 A1 Var10 A2 Var11 A100. COMPUTE Subject = !I. FORMAT Subject (F4.0). SAVE OUTFILE = !IV01outpath + !QUOTE(!CONCAT('S', !I, '_IV1.sav')) /KEEP Subject Var1 TO Var11. !DOEND. !ENDDEFINE. |
At 05:02 PM 11/30/2006, Rebecca wrote:
>I'm trying to build a macro that takes a text file, brings it into >spss, computes a new variable based on the id number of the file, and >spits out an spss file. > >The macro works fine if I type in a generic filename in the fourth >line of the long macro (for the get data file name). So, the following catenation below IS working, right? >SAVE OUTFILE = !IV01outpath + !QUOTE(!CONCAT('S', !I, '_IV1.sav')) > /KEEP Subject Var1 TO Var11. And this catenation isn't: >GET DATA /TYPE = TXT > /FILE = !IV01path + !CONCAT('!IV01nameS' !I) Is it as simple as the missing comma between "'!IV01nameS'" and "!I"? The following is SPSS draft output, with the second expansion terminated after the first loop iteration. Unfortunately, I don't know what to make of the error message >Error. Command name: GET DATA >(2256) Invalid subcommand: FILE >This command not executed. unless it's about the braces ("<>") making the filename invalid, which they do. (I haven't tried to make code that actually works.) The other error messages are just propagation of errors, after the GET DATA was invalid. ***MACROS for filepath and filenames. DEFINE !IV01path () < really long filepath> !ENDDEFINE. DEFINE !IV01outpath () <filepath> !ENDDEFINE. DEFINE !IV01nameS1001 () <ridiculously long unstandardized filenaming convention> !ENDDEFINE. DEFINE !IV01nameS1002 ()<ridiculously long unstandardized filenaming convention> !ENDDEFINE. DEFINE !IV01nameS1003 ()<ridiculously long unstandardized filenaming convention> !ENDDEFINE. DEFINE !GETFILE (). !DO !I = 1001 !TO 1020. GET DATA /TYPE = TXT /FILE = !IV01path + !CONCAT('!IV01nameS' !I). >Error # 6834 in column 43. Text: !I >In a macro expression, an operand was not preceded by an operator. >This command not executed. COMPUTE Subject = !I. FORMAT Subject (F4.0). SAVE OUTFILE = !IV01outpath + !QUOTE(!CONCAT('S', !I, '_IV1.sav')) /KEEP Subject Var1 TO Var11. !DOEND. !ENDDEFINE. PRESERVE. SET MPRINT ON. !GETFILE 101 M> !GETFILE >Error # 1. Command name: !GETFILE >The first word in the line is not recognized as an SPSS command. >This command not executed. 102 M> RESTORE. 103 M> RESTORE. DEFINE !GET_2 (). !DO !I = 1001 !TO 1020. GET DATA /TYPE = TXT /FILE = !IV01path + !CONCAT('!IV01nameS', !I). COMPUTE Subject = !I. FORMAT Subject (F4.0). SAVE OUTFILE = !IV01outpath + !QUOTE(!CONCAT('S', !I, '_IV1.sav')) /KEEP Subject Var1 TO Var11. !DOEND. !ENDDEFINE. PRESERVE. SET MPRINT ON. !GET_2 118 M> 119 M> . 120 M> 121 M> GET DATA /TYPE = TXT /FILE = < really long filepath> 122 M> + <ridiculously long unstandardized filenaming convention> 123 M> . >Error. Command name: GET DATA >(2256) Invalid subcommand: FILE >This command not executed. 124 M> COMPUTE Subject = 1001. >Error # 100. Command name: COMPUTE >This command is not permitted before the beginning of file definition >commands. >This command not executed. 125 M> FORMAT Subject (F4.0). >Error # 100. Command name: FORMAT >This command is not permitted before the beginning of file definition >commands. >This command not executed. 126 M> SAVE OUTFILE = <filepath> |
Free forum by Nabble | Edit this page |