Hi,
is there a way to have a macro, which could generate a n times m matrix when n and m considered as an input? If I want to assign row 2 column 3 as 1 and 2, how to do that in a SPSS macro? Thanks, |
Administrator
|
Perhaps you could provide an illustration of what you are trying to do.Meanwhile look up DEFINE in the FM. Also see MAKE function in the MATRIX language.
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?" |
Thanks, what I am trying to do is a macro that allows inputs of number of rows and number of columns, and it output a data with dimension n times m, and the cells values are all blank. After this, I need to have a function to be able to assign values to a specific cell. Not sure if I express myself clearly. could you please provide a link for " MAKE function in the MATRIX language."? what is "FM" as you mentioned? On Mon, Jun 22, 2015 at 9:42 PM, David Marso [via SPSSX Discussion] <[hidden email]> wrote: Perhaps you could provide an illustration of what you are trying to do.Meanwhile look up DEFINE in the FM. Also see MAKE function in the MATRIX language. |
Administrator
|
FM = "Fine Manual" (aka., the Command Syntax Reference manual)
RTFM = read the FM In the FM, you'll find info about the MAKE function here: MATRIX - END MATRIX > COMPUTE Statement > Matrix Functions HTH.
--
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 albert_sun
/* Untested */.
DEFINE Make_Matrix (!POS !TOKENS(1) / !POS !TOKENS(1) ) MATRIX. SAVE MAKE(!1,!2,0) /OUTFILE * /VARIABLES x1 TO !CONCAT(x,!2). END MATRIX. !ENDDEFINE . DEFINE Set_Value (!POS !TOKENS(1) / !POS !TOKENS(1) / !POS !TOKENS(1) ) MATRIX. GET data / FILE * /NAMES=varnames . COMPUTE data(!1,!2)=!3. SAVE data / FILE * / NAMES=varnames. END MATRIX. !ENDDEFINE. Make_Matrix 100000 100000 . Set_Value 2 1 1000.
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?" |
What is the context in which you would be doing this?
Is this a one-off? perhaps you just mean some syntax? Are you trying to do some form of simulation? Can it be done using the simulation procedures?
Art Kendall
Social Research Consultants |
In reply to this post by albert_sun
At 07:49 AM 6/22/2015, albert_sun wrote:
>what I am trying to do is a macro that allows inputs of number of >rows and number of columns, and it output a data with dimension n >times m, and the cells values are all blank. After this, I need to >have a function to be able to assign values to a specific cell. Not >sure if I express myself clearly. Do I read this right? You want to create an SPSS dataset with n records ('cases' in the SPSS documentation) and m variables, all numeric and all 'blank', i.e. system-missing; and then add data. If I understand you rightly, what you're doing is clumsy in SPSS: SPSS doesn't readily add data to existing records (it can be and is done), but easily adds new records to an existing file, which may be empty or not. Can you tell us how you determine what values should go in each cell in the final result? That will help us understand your problem much better; and, very possibly, give a solution that won't require building the empty matrix, and won't need macro or Python code at all. -Best of luck, Richard Ristow ===================== 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 |
At 04:36 PM 6/22/2015, I wrote:
>At 07:49 AM 6/22/2015, albert_sun wrote: > >>what I am trying to do is a macro that allows inputs of number of >>rows and number of columns, and it output a data with dimension n >>times m, and the cells values are all blank. After this, I need to >>have a function to be able to assign values to a specific cell. Not >>sure if I express myself clearly. > >Do I read this right? You want to create an SPSS dataset with n >records ('cases' in the SPSS documentation) and m variables, all >numeric and all 'blank', i.e. system-missing; and then add data. I don't see that this thread was ever resolved, so here's a quick solution to the problem, as I guessed you intended. It's in native SPSS code, not using a macro, but it could be made into a macro, taking m and n as parameters. I've added a variable "Row#" to each row. NEW FILE. INPUT PROGRAM. . NUMERIC Row# (F4). . VECTOR VAL (4,F6.2) /* For 4 columns ('cases') */. . LOOP Row# = 1 TO 6 /* For 6 rows ('variables') */. . END CASE. . END LOOP. END FILE. END INPUT PROGRAM. LIST. List |-----------------------------|---------------------------| |Output Created |24-JUN-2015 18:03:14 | |-----------------------------|---------------------------| Row# VAL1 VAL2 VAL3 VAL4 1 . . . . 2 . . . . 3 . . . . 4 . . . . 5 . . . . 6 . . . . Number of cases read: 6 Number of cases listed: 6 ============== APPENDIX: Code ============== NEW FILE. INPUT PROGRAM. . NUMERIC Row# (F4). . VECTOR VAL (4,F6.2) /* For 4 columns ('cases') */. . LOOP Row# = 1 TO 6 /* For 6 rows ('variables') */. . END CASE. . END LOOP. END FILE. END INPUT PROGRAM. LIST. ===================== 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 |