writing this is for a non-python user.
Is there a cleaner way to simply pass in the string eps than this? DEFINE @aaa() eps !ENDDEFINE. DEFINE !savefile (fn=!TOKENS(1)) get FILE=!QUOTE(!CONCAT("K:\eps_year_2009.sav")). !enddefine. !savefile fn=@aaa. |
I'm confused - the !savefile macro (that gets a file?) will always expand to the same thing, as !fn is not invoked anywhere within the function. So what is your question exactly?
|
Administrator
|
I share Andy's confusion. Is the OP possibly looking for FILE HANDLE functionality? Here are some examples from the FM:
FILE HANDLE thisMonthFile /NAME='/sales/data/july.sav'. FILE HANDLE dataDirectory /NAME='/sales/data'. GET FILE 'thisMonthFile'. GET FILE 'dataDirectory/july.sav'.
--
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/). |
Sorry to confuse.
@aaa is getting its value passed in not from SPSS. We had this program built by an ouside vender. So @aaa '' will become @aaa somethignDefinedbyUser. Does that help? |
Not really, is this for a production job? Your example problem is a non-problem, you could just have the @ (user prompt?) inserted whereever you want, whether it is within usual syntax or a macro definition makes no difference. So I'm not sure what your question is or what the problem is.
|
I'm not sure how to use the user prompt to fill in a string?
DEFINE @aaa() oct11 !ENDDEFINE. get FILE='I:\MediCalData\meds_'+@aaa+'Oct11_uncut.sav'. Also, I can't get the multiline macro to work. Any ideas? DEFINE !getfile (fn=!TOKENS(1)) get FILE=!QUOTE(!CONCAT("GET DATA /TYPE = TXT /FILE = '\\Covenas\mis_dwnld\STATE_MEDS FILES\MEDS_",!fn,"_1779.TXT' /FIXCASE = 1 /ARRANGEMENT = FIXED /FIRSTCASE = 1 /IMPORTCASE = ALL /VARIABLES = /1 ssn 0-8 f9.0 ... more variables ... continue code... . CACHE.")). !enddefine. !getfile fn=@aaa. Thank you everyone, Chet |
Hmm - your examples are still very strange. Here is my best guess based on info so far for what you want to do.
DEFINE !getfile (fn=!TOKENS(1)) !LET !myfile = !QUOTE(!CONCAT('I:\MediCalData\meds_',!fn,'Oct11_uncut.sav')) get file = !myfile. !ENDDEFINE. Or similarly without the !LET command, DEFINE !getfile (fn=!TOKENS(1)) !LET !myfile = !QUOTE(!CONCAT('I:\MediCalData\meds_',!fn,'Oct11_uncut.sav')) get file = !QUOTE(!CONCAT('I:\MediCalData\meds_',!fn,'Oct11_uncut.sav')). !ENDDEFINE. For the second example, you are correct you can't have the command split across lines. Your example there is no need to split across lines though, and it works pretty much the same way as the above examples. E.g. DEFINE !getfile (fn=!TOKENS(1)) !LET !myfile = !QUOTE(!CONCAT('\\Covenas\mis_dwnld\STATE_MEDS FILES\MEDS_",!fn,"_1779.TXT')) GET DATA /TYPE = TXT /FILE = !myfile /FIXCASE = 1 /ARRANGEMENT = FIXED /FIRSTCASE = 1 /IMPORTCASE = ALL /VARIABLES = /1 ssn 0-8 f9.0 *... more variables. *... continue code... . CACHE. !enddefine. It is late here, but your example code snippets are so strange I can't tell if your confused about how macros work, or you just aren't explaining your situation correctly. Your last example even if it worked the way you wanted would expand to something like [GET FILE = GET DATA = ....] I am also very confused why you are writing as if you need to have two macro statements (there are situations in which this is called for - more modular code etc. - but you haven't illustrated a need here that I can tell). |
In reply to this post by ChetMeinzer
----- Original Message -----
> From: ChetMeinzer <[hidden email]> > To: [hidden email] > Cc: > Sent: Friday, July 12, 2013 8:14 PM > Subject: [SPSSX-L] Is there a better macro for passing string values? > > writing this is for a non-python user. > > Is there a cleaner way to simply pass in the string eps than this? > > DEFINE > @aaa() eps > !ENDDEFINE. > > DEFINE !savefile (fn=!TOKENS(1)) > get FILE=!QUOTE(!CONCAT("K:\eps_year_2009.sav")). > !enddefine. > > !savefile fn=@aaa. Huh? A macro that gets a file is called "savefile"? What would be a beter, more descriptive name for the @aaa user prompt? I usually define two file handles at the beginning of the syntax. One is for interactive use, the other is for use with the production facility. One of the file handles is always outcommented. Repeating the @ sign throughout the syntax makes is less easy to use in interactive mode. *FILE HANDLE fn /NAME = "d:/temp/someFile.sav". /* interactive use. FILE HANDLE fn /NAME = "@fn". /* batch use --> fn is one of the params in the .bat file. GET FILE = fn. .... ===================== 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 |
In reply to this post by Andy W
I apologize for my poor explanation, and really appreciate your help. I did mistakenly put an extra 'get file' in my example (thanks for catching that, I'm new to macros).
My situation is that the variable is getting passed into the syntax file, and I want the macro to receive it. I won't actually be defining the var, but that's a way to test it. The multiple line problem is an issue because the length of the statement extends beyond spss's line limit (I'm pulling specific vars among many more). Thanks again, C Sent from mobile On Jul 12, 2013, at 20:05, "Andy W [via SPSSX Discussion]" <[hidden email]<mailto:[hidden email]>> wrote: Hmm - your examples are still very strange. Here is my best guess based on info so far for what you want to do. DEFINE !getfile (fn=!TOKENS(1)) !LET !myfile = !QUOTE(!CONCAT('I:\MediCalData\meds_',!fn,'Oct11_uncut.sav')) get file = !myfile. !ENDDEFINE. Or similarly without the !LET command, DEFINE !getfile (fn=!TOKENS(1)) !LET !myfile = !QUOTE(!CONCAT('I:\MediCalData\meds_',!fn,'Oct11_uncut.sav')) get file = !QUOTE(!CONCAT('I:\MediCalData\meds_',!fn,'Oct11_uncut.sav')). !ENDDEFINE. For the second example, you are correct you can't have the command split across lines. Your example there is no need to split across lines though, and it works pretty much the same way as the above examples. E.g. DEFINE !getfile (fn=!TOKENS(1)) !LET !myfile = !QUOTE(!CONCAT('\\Covenas\mis_dwnld\STATE_MEDS FILES\MEDS_",!fn,"_1779.TXT')) GET DATA /TYPE = TXT /FILE = !myfile /FIXCASE = 1 /ARRANGEMENT = FIXED /FIRSTCASE = 1 /IMPORTCASE = ALL /VARIABLES = /1 ssn 0-8 f9.0 *... more variables. *... continue code... . CACHE. !enddefine. It is late here, but your example code snippets are so strange I can't tell if your confused about how macros work, or you just aren't explaining your situation correctly. Your last example even if it worked the way you wanted would expand to something like [GET FILE = GET DATA = ....] I am also very confused why you are writing as if you need to have two macro statements (there are situations in which this is called for - more modular code etc. - but you haven't illustrated a need here that I can tell). Andy W [hidden email]<mailto:[hidden email]> http://andrewpwheeler.wordpress.com/ ________________________________ If you reply to this email, your message will be added to the discussion below: http://spssx-discussion.1045642.n5.nabble.com/Is-there-a-better-macro-for-passing-string-values-tp5721140p5721154.html To unsubscribe from Is there a better macro for passing string values?, click here< NAML<http://spssx-discussion.1045642.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml> |
Free forum by Nabble | Edit this page |