|
|
Hi!
You're trying to assigning to the string "G4max", which has no meaning. It does not refer to the maximum. You could use WRITE and INSERT to assign it to a macro, but that's extremely ugly, so here's an alternative solution: file handle f / name = 'c:/program files/spss/employee data.sav'. get file = f. compute dummy = 1. aggr out = * / break = dummy / max = max (educ). add files / file = * / keep = max. begin program. import spss cur = spss.Cursor() max = int(cur.fetchone()[0]) cur.close() for period in range(1, max+1): spss.Submit("get file = f.") #spss.Submit("numeric g4id4 to g4id9 (f4).") # not needed in your dataset, only for testing spss.Submit("temporary.") spss.Submit("select if any(%s, g4id4 to g4id9)." % period) spss.Submit("compute report_owner = %s." % period) spss.Submit("save outfile = 'd:/temp/id_%02d.sav'." % period) end program. Cheers!! Albert-Jan ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ --- On Thu, 10/8/09, David Futrell <[hidden email]> wrote: > From: David Futrell <[hidden email]> > Subject: [SPSSX-L] Simple (I think) problem with a Macro > To: [hidden email] > Date: Thursday, October 8, 2009, 4:25 PM > > Hi everyone: > > I have an annoying problem > with a macro that I hope someone can help me solve. > > The following syntax works > perfectly. > > DEFINE !REPORTMACRO(). > > !DO !I=1 !TO 865 > temporary. > select if any(!I,g4id1 to g4id9). > > compute report_owner=!I. > save > outfile=!QUOTE(!CONCAT("D:\Monthly Pulse > Survey\G4 Reports\ID > ",!I,".sav.")) > /keep report_owner empid. > !DOEND > > !ENDDEFINE > > !REPORTMACRO. > > > > However, I want to use a calculated value in the !DO line > instead of > the constant (in this case 865) because this value varies > across reporting periods and I currently have to calculate > it and manually enter the value into the macro. > > I can easily calculate what > the end value should be using the aggregate command. > Here's what I've tried to do: > > > compute max_x=max(g4id1 to g4id10). > AGGREGATE > /OUTFILE=* MODE=ADDVARIABLES > > /BREAK= > > /G4max=MAX(max_x). > > > DEFINE > !REPORTMACRO(). > > !DO !I=1 !TO G4max > temporary. > select if any(!I,g4id1 to g4id9). > > compute report_owner=!I. > save > outfile=!QUOTE(!CONCAT("D:\Monthly Pulse > Survey\G4 Reports\ID > ",!I,".sav.")) > /keep report_owner empid. > !DOEND > > !ENDDEFINE > > > !REPORTMACRO. > > > The calculated value (G4max) > is exactly 865, but when I try the syntax, I get this > message: > > > >Warning # 228 > >Invalid string found where > numeric value required in macro expression. > > >Warning # 221 > >Macro expansion found an error > interpreting an operation code. Check the > >arguments to functions and loop > parameters for valid values. > > >Error # 1. > Command name: !ERROR_MACRO > >The first word in the line is > not recognized as an SPSS Statistics command. > >This command not > executed. > > Any ideas? > > David Futrell > Eli Lilly and > Company > > > > > > ===================== 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 all listers!
This statement is not working. This is all on one line: if (elig_period = 1) & ((fromdatesvc_s >= app_30_days.1) & (fromdatesvc_s >= elig_start_date.1) & This is on a second line indented 31 spaces: (fromdatesvc_s < app_first_of_month.1) & (fromdatesvc_s <= elig_end_date.1)) no_pay_30 = 1. It is supposed to identify a claim that occurred with eligibility period 1 (individuals can have more than one eligibility period). It should then flag only those claims that are within 30 days of the first of the month that the application for the program was filed, where the date of service is greater than the date of the beginning of eligibility, is less than the first of the month when the application was completed, and less than the end of the eligibility period. The problem is that the statement seems to be ignoring some stipulations. I've been able to identify that it is not selecting dates of service that are less than the first of the month that the application took place in. Could my indentation have something to do with it? I indent all the time to make my code more readable! Thanks Matt Matthew Pirritano, Ph.D. Research Analyst IV Medical Services Initiative (MSI) Orange County Health Care Agency (714) 568-5648 ===================== 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 David Futrell
You cannot directly transfer a data value to a macro in this
way. You are getting this error because G4max in the macro is just a string
value. Macros are really, really limited (e.g., dumb). In the past clever
SPSSers would do things like generate macros on the fly by using the WRITE command
to create a syntax file with some interspersed data values. Now, the best way
to do this is to use Python to generate the syntax and run it because Python
knows about the contents of the dictionary (variable names and such) and can
retrieve case values. From: SPSSX(r) Discussion
[mailto:[hidden email]] On Behalf Of David Futrell
|
|
In reply to this post by mpirritano
Matt,
Maybe somebody else can see the problem without seeing sample data but it would sure be helpful if you could post data where the selection failed and where it suceeded. And, probably some explanation of the variables. It seems to me that since you got not error statement, you must not have any error related to indention (or any other cause). And, in any event, indention as part of a continuation should not give an error. Thanks, Gene Maguin >>This statement is not working. This is all on one line: if (elig_period = 1) & ((fromdatesvc_s >= app_30_days.1) & (fromdatesvc_s >= elig_start_date.1) & This is on a second line indented 31 spaces: (fromdatesvc_s < app_first_of_month.1) & (fromdatesvc_s <= elig_end_date.1)) no_pay_30 = 1. It is supposed to identify a claim that occurred with eligibility period 1 (individuals can have more than one eligibility period). It should then flag only those claims that are within 30 days of the first of the month that the application for the program was filed, where the date of service is greater than the date of the beginning of eligibility, is less than the first of the month when the application was completed, and less than the end of the eligibility period. The problem is that the statement seems to be ignoring some stipulations. I've been able to identify that it is not selecting dates of service that are less than the first of the month that the application took place in. Could my indentation have something to do with it? I indent all the time to make my code more readable! Thanks Matt Matthew Pirritano, Ph.D. Research Analyst IV Medical Services Initiative (MSI) Orange County Health Care Agency (714) 568-5648 ===================== 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 |
|
Administrator
|
In reply to this post by David Futrell
Here's a method that seemed to work on an example I tried with the GSS data file. (I.e., there were no error messages when I ran the lines that define the macro, including the INCLUDE FILE line. But I couldn't actually run the macro, given that I didn't have the right data file.) It's probably not as neat as the Python method that was posted...but it does entail only a fairly minor tweak on what you've already got. compute max_x=max(g4id1 to g4id10). AGGREGATE /OUTFILE=* MODE=ADDVARIABLES /BREAK= /G4max=MAX(max_x). * Write the first two lines of the macro definition to a text file . do if $casenum EQ 1. - write outfile = "D:\myfolder\macro_lines.txt" / "DEFINE !REPORTMACRO()." / "!DO !I=1 !TO ", G4max . end if. exe. * Now use INCLUDE FILE to bring in the first two lines of the macro. include file = "D:\myfolder\macro_lines.txt" . /* first two lines of macro definition . * Now the rest of the macro definition . temporary. select if any(!I,g4id1 to g4id9). compute report_owner=!I. save outfile=!QUOTE(!CONCAT("D:\Monthly Pulse Survey\G4 Reports\ID ",!I,".sav.")) /keep report_owner empid. !DOEND !ENDDEFINE
--
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/). |
|
Administrator
|
In reply to this post by mpirritano
Hi Matt. I find that for complicated conditional statements, it often helps to make the statement more readable (by reducing clutter) if I use a bunch of scratch variables for the various conditions. E.g., compute #ep1 = (elig_period EQ 1). compute #fdGEa30 = (fromdatesvc_s GE app_30_days.1). compute #fdGEesd1 = (fromdatesvc_s GE elig_start_date.1). etc... if #ep1 & (#fdGEa30 & #fdGEesd1 & ...
--
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/). |
|
Administrator
|
In reply to this post by ViAnn Beadle
This is not meant in any way to question the merits of Python--I have no doubt that it is superior in many ways to the macro language. However, one clear advantage of macros is that they do not require installation of Python. This may not be an issue for some folks, but I know that many of the colleagues with whom I share code will never install Python (or anything else) that is not part of the base installation. It's hard enough getting some of them to install the latest patches. ;-)
--
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/). |
|
There are an increasingly large number of additional "packaged" python
programs available on SPSS Devcentral that someday your colleagues might find to be very, very useful. Unfortunately, finding those programs and what they actually do is a bit complicated. I have to resort to searches on the text in a very long page of modules and I don't think that Google has any bots running around on the site to help. The common problems of open-source initiatives like this seem to be the short update cycles with version incompatibilities, decentralization of code (multiple installs, copying, etc.), less than comprehensive or hard to find documentation, and the decentralization of information on access. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver Sent: Friday, October 09, 2009 5:19 AM To: [hidden email] Subject: Re: Simple (I think) problem with a Macro ViAnn Beadle wrote: > > You cannot directly transfer a data value to a macro in this way. You are > getting this error because G4max in the macro is just a string value. > Macros > are really, really limited (e.g., dumb). In the past clever SPSSers would > do > things like generate macros on the fly by using the WRITE command to > create > a syntax file with some interspersed data values. Now, the best way to do > this is to use Python to generate the syntax and run it because Python > knows > about the contents of the dictionary (variable names and such) and can > retrieve case values. > This is not meant in any way to question the merits of Python--I have no doubt that it is superior in many ways to the macro language. However, one clear advantage of macros is that they do not require installation of Python. This may not be an issue for some folks, but I know that many of the colleagues with whom I share code will never install Python (or anything else) that is not part of the base installation. It's hard enough getting some of them to install the latest patches. ;-) ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://www.nabble.com/Simple-%28I-think%29-problem-with-a-Macro-tp25805207p2 5819389.html Sent from the SPSSX Discussion mailing list archive at 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 ===================== 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 |
|
Administrator
|
As noted previously, I don't doubt at all the usefulness of Python. But to reinforce the point I made earlier, here is the result of a quick poll I just took (n=1). My office neighbour, a long-time SPSS user, has never even heard of Python or R. And she is by no means a novice point-and-click user. Rather, she is quite well-versed in the use of syntax for descriptive stats, graphs, regression models (linear, logistic), ANOVA, etc. She even includes comments in her syntax. AFAIK, she has never used macros or the matrix language. In short, I think she is quite representative of a lot of academic users. I also think it is easy to forget that those of us who lurk on mailing lists like this (or in the usenet newsgroup) are probably not very representative of most users. Bruce
--
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/). |
|
It's always easy to pick your sample;-) Here's what she might be missing:
- Data and dictionary aware macros (which started this thread off). Python can even provide a point and click interface for your macro. - Casewise transformations not available via standard SPSS transformation commands and functions - Database functions not available via MATCH FILES or ADD FILES - Programmed pivot table edits including pivoting, hiding, merging tables, and cell properties. - Specialized statistical procedures I seems to recall at least 10 people looking for raking on this list and that's available via a packaged application. Here are some applications which posters on this list have been looking for: - Case control matching - TURF analysis - Partial Least Squares - Confidence Intervals for Proportion - Compare Datasets And we shouldn't forget about the interface to R. -----Original Message----- From: SPSSX(r) Discussion [mailto:[hidden email]] On Behalf Of Bruce Weaver Sent: Friday, October 09, 2009 10:06 AM To: [hidden email] Subject: Re: Python (was Simple (I think) problem with a Macro) ViAnn Beadle wrote: > > There are an increasingly large number of additional "packaged" python > programs available on SPSS Devcentral that someday your colleagues might > find to be very, very useful. Unfortunately, finding those programs and > what > they actually do is a bit complicated. I have to resort to searches on the > text in a very long page of modules and I don't think that Google has any > bots running around on the site to help. > > The common problems of open-source initiatives like this seem to be the > short update cycles with version incompatibilities, decentralization of > code > (multiple installs, copying, etc.), less than comprehensive or hard to > find > documentation, and the decentralization of information on access. > > As noted previously, I don't doubt at all the usefulness of Python. But to reinforce the point I made earlier, here is the result of a quick poll I just took (n=1). My office neighbour, a long-time SPSS user, has never even heard of Python or R. And she is by no means a novice point-and-click user. Rather, she is quite well-versed in the use of syntax for descriptive stats, graphs, regression models (linear, logistic), ANOVA, etc. She even includes comments in her syntax. AFAIK, she has never used macros or the matrix language. In short, I think she is quite representative of a lot of academic users. I also think it is easy to forget that those of us who lurk on mailing lists like this (or in the usenet newsgroup) are probably not very representative of most users. Bruce ----- -- Bruce Weaver [hidden email] http://sites.google.com/a/lakeheadu.ca/bweaver/ "When all else fails, RTFM." NOTE: My Hotmail account is not monitored regularly. To send me an e-mail, please use the address shown above. -- View this message in context: http://www.nabble.com/Simple-%28I-think%29-problem-with-a-Macro-tp25805207p2 5823745.html Sent from the SPSSX Discussion mailing list archive at 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 ===================== 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 |
| Free forum by Nabble | Edit this page |
