I have written a macro which generates syntax to run VARSTOCASES command. The purpose of the macro is so a user can easily paste in the variables in the order as they appear in the data file and then the macro re-arranges them in the appropriate format for use in VARSTOCASES syntax. See below for macro with an example.
The macro works fine when the number of variables entered in the "vars" parameter is relatively 'small'. I've not yet figured out the threshold for 'small'. But when there is a long list of variables (300+) then the macro takes extremely long time to either kick in or even get started in the first place.
It either
One thing to note is that, if I manually generate the syntax manually and run the VARSTOCASES command then it runs without any hindrance. So it seems to be the macros attempt to generate the syntax being problematic (with all the looping that's going on?)?
I'd like to question whether this is some limitation in the use of DEFINE (and !DO loops within DEFINE) or perhaps in the way I have coded the macro to achieve the desired result. If the latter (which would be my guess!), would there be a alternative way to code the macro to use less memory(?), loops(?) and simply be more efficient?
Many thanks in advance! Jignesh define !VarsToCasesMacro (vars = !charend('/') / nbVars = !charend('/') / prefix = !charend('/') / indexname = !charend('/') !default ('Index')) set mprint on. /* ------------------------------------------------------ */ /* calculate total number of vars */ /* ------------------------------------------------------ */ !let !counter1=!blanks(0) !do !i !in (!vars) !let !counter1=!concat(!counter1,!blanks(1)) !doend !let !TotalnbVars=!len(!counter1) /* ------------------------------------------------------ */ /* modulus of !TotalnbVars / !nbVars, using loops */ /* ------------------------------------------------------ */ /* if we don't have a division-by-zero error... */ !if (!nbVars <> 0) !then !let !answer = 0 /* do division */ !do !y = !TotalnbVars !to !nbVars !by -!nbVars !doend /* modulus = !y - !nbVars */ !let !first = true !do !x = !y !to 0 !by -!nbVars !if (!first = true) !then !let !first = false !else !let !answer = !x !break !ifend !doend !ifend !if (!answer <>0) !then /*do nothing*/ !else /* ------------------------------------------------------ */ /* generate vartocases syntax */ /* ------------------------------------------------------ */ varstocases !let !varsTail=!vars !do !start=1 !to !nbVars !let !varsHead=!head(!varsTail) !let !varsTail=!tail(!varsTail) !let !from=!null !do !i = !start !to !TotalnbVars !by !nbVars !let !counter2=!blanks(0) !do !j !in (!vars) !let !counter2=!concat(!counter2,!blanks(1)) !let !varindex=!len(!counter2) !if (!i=!varindex) !then !let !from=!concat(!from," ",!j) !ifend !doend !doend !if (!prefix<>!null) !then !let !varshead=!concat(!prefix,!start) !ifend /make !varshead from !from !doend /index = !indexname. !ifend set mprint off. !enddefine. !VarsToCasesMacro vars= A1 A2 A3 A4 A5 B1 B2 B3 B4 B5 C1 C2 C3 C4 C5 /nbvars=5. Syntax generated by macro: varstocases /make A1 from A1 B1 C1 /make A2 from A2 B2 C2 /make A3 from A3 B3 C3 /make A4 from A4 B4 C4 /make A5 from A5 B5 C5 /index = Index. |
hello, It seems unnecessary to have three nested loops in the bottom part of your code. But how about the code below? It's trivial to convert it to a function: import string, spss makeCmds = ["/make %s%s from %s%s %s%s %s%s" % (letter, i, letter, i, letters[i+1], i, letters[i+2], i) for letter in letters[:24] for i in range(10)] spss.Submit("varstocases " + "\r\n ".join(makeCmds) + " /index = Index.") this submits the following code: varstocases /make A0 from A0 B0 C0 /make A1 from A1 C1 D1 /make A2 from A2 D2 E2 /make A3 from A3 E3 F3 /make A4 from A4 F4 G4 /make A5 from A5 G5 H5 /make A6 from A6 H6 I6 /make A7 from A7 I7 J7 /make A8 from A8 J8 K8 /make A9 from A9 K9 L9 /make B0 from B0 B0 C0 /make B1 from B1 C1 D1 /make B2 from B2 D2 E2 /make B3 from B3 E3 F3 /make B4 from B4 F4 G4 /make B5 from B5 G5 H5 /make B6 from B6 H6 I6 /make B7 from B7 I7 J7 /make B8 from B8 J8 K8 /make B9 from B9 K9 L9 /make C0 from C0 B0 C0 /make C1 from C1 C1 D1 /make C2 from C2 D2 E2 /make C3 from C3 E3 F3 /make C4 from C4 F4 G4 /make C5 from C5 G5 H5 /make C6 from C6 H6 I6 /make C7 from C7 I7 J7 /make C8 from C8 J8 K8 /make C9 from C9 K9 L9 /make D0 from D0 B0 C0 /make D1 from D1 C1 D1 /make D2 from D2 D2 E2 /make D3 from D3 E3 F3 /make D4 from D4 F4 G4 /make D5 from D5 G5 H5 /make D6 from D6 H6 I6 /make D7 from D7 I7 J7 /make D8 from D8 J8 K8 /make D9 from D9 K9 L9 /make E0 from E0 B0 C0 /make E1 from E1 C1 D1 /make E2 from E2 D2 E2 /make E3 from E3 E3 F3 /make E4 from E4 F4 G4 /make E5 from E5 G5 H5 /make E6 from E6 H6 I6 /make E7 from E7 I7 J7 /make E8 from E8 J8 K8 /make E9 from E9 K9 L9 /make F0 from F0 B0 C0 /make F1 from F1 C1 D1 /make F2 from F2 D2 E2 /make F3 from F3 E3 F3 /make F4 from F4 F4 G4 /make F5 from F5 G5 H5 /make F6 from F6 H6 I6 /make F7 from F7 I7 J7 /make F8 from F8 J8 K8 /make F9 from F9 K9 L9 /make G0 from G0 B0 C0 /make G1 from G1 C1 D1 /make G2 from G2 D2 E2 /make G3 from G3 E3 F3 /make G4 from G4 F4 G4 /make G5 from G5 G5 H5 /make G6 from G6 H6 I6 /make G7 from G7 I7 J7 /make G8 from G8 J8 K8 /make G9 from G9 K9 L9 /make H0 from H0 B0 C0 /make H1 from H1 C1 D1 /make H2 from H2 D2 E2 /make H3 from H3 E3 F3 /make H4 from H4 F4 G4 /make H5 from H5 G5 H5 /make H6 from H6 H6 I6 /make H7 from H7 I7 J7 /make H8 from H8 J8 K8 /make H9 from H9 K9 L9 /make I0 from I0 B0 C0 /make I1 from I1 C1 D1 /make I2 from I2 D2 E2 /make I3 from I3 E3 F3 /make I4 from I4 F4 G4 /make I5 from I5 G5 H5 /make I6 from I6 H6 I6 /make I7 from I7 I7 J7 /make I8 from I8 J8 K8 /make I9 from I9 K9 L9 /make J0 from J0 B0 C0 /make J1 from J1 C1 D1 /make J2 from J2 D2 E2 /make J3 from J3 E3 F3 /make J4 from J4 F4 G4 /make J5 from J5 G5 H5 /make J6 from J6 H6 I6 /make J7 from J7 I7 J7 /make J8 from J8 J8 K8 /make J9 from J9 K9 L9 /make K0 from K0 B0 C0 /make K1 from K1 C1 D1 /make K2 from K2 D2 E2 /make K3 from K3 E3 F3 /make K4 from K4 F4 G4 /make K5 from K5 G5 H5 /make K6 from K6 H6 I6 /make K7 from K7 I7 J7 /make K8 from K8 J8 K8 /make K9 from K9 K9 L9 /make L0 from L0 B0 C0 /make L1 from L1 C1 D1 /make L2 from L2 D2 E2 /make L3 from L3 E3 F3 /make L4 from L4 F4 G4 /make L5 from L5 G5 H5 /make L6 from L6 H6 I6 /make L7 from L7 I7 J7 /make L8 from L8 J8 K8 /make L9 from L9 K9 L9 /make M0 from M0 B0 C0 /make M1 from M1 C1 D1 /make M2 from M2 D2 E2 /make M3 from M3 E3 F3 /make M4 from M4 F4 G4 /make M5 from M5 G5 H5 /make M6 from M6 H6 I6 /make M7 from M7 I7 J7 /make M8 from M8 J8 K8 /make M9 from M9 K9 L9 /make N0 from N0 B0 C0 /make N1 from N1 C1 D1 /make N2 from N2 D2 E2 /make N3 from N3 E3 F3 /make N4 from N4 F4 G4 /make N5 from N5 G5 H5 /make N6 from N6 H6 I6 /make N7 from N7 I7 J7 /make N8 from N8 J8 K8 /make N9 from N9 K9 L9 /make O0 from O0 B0 C0 /make O1 from O1 C1 D1 /make O2 from O2 D2 E2 /make O3 from O3 E3 F3 /make O4 from O4 F4 G4 /make O5 from O5 G5 H5 /make O6 from O6 H6 I6 /make O7 from O7 I7 J7 /make O8 from O8 J8 K8 /make O9 from O9 K9 L9 /make P0 from P0 B0 C0 /make P1 from P1 C1 D1 /make P2 from P2 D2 E2 /make P3 from P3 E3 F3 /make P4 from P4 F4 G4 /make P5 from P5 G5 H5 /make P6 from P6 H6 I6 /make P7 from P7 I7 J7 /make P8 from P8 J8 K8 /make P9 from P9 K9 L9 /make Q0 from Q0 B0 C0 /make Q1 from Q1 C1 D1 /make Q2 from Q2 D2 E2 /make Q3 from Q3 E3 F3 /make Q4 from Q4 F4 G4 /make Q5 from Q5 G5 H5 /make Q6 from Q6 H6 I6 /make Q7 from Q7 I7 J7 /make Q8 from Q8 J8 K8 /make Q9 from Q9 K9 L9 /make R0 from R0 B0 C0 /make R1 from R1 C1 D1 /make R2 from R2 D2 E2 /make R3 from R3 E3 F3 /make R4 from R4 F4 G4 /make R5 from R5 G5 H5 /make R6 from R6 H6 I6 /make R7 from R7 I7 J7 /make R8 from R8 J8 K8 /make R9 from R9 K9 L9 /make S0 from S0 B0 C0 /make S1 from S1 C1 D1 /make S2 from S2 D2 E2 /make S3 from S3 E3 F3 /make S4 from S4 F4 G4 /make S5 from S5 G5 H5 /make S6 from S6 H6 I6 /make S7 from S7 I7 J7 /make S8 from S8 J8 K8 /make S9 from S9 K9 L9 /make T0 from T0 B0 C0 /make T1 from T1 C1 D1 /make T2 from T2 D2 E2 /make T3 from T3 E3 F3 /make T4 from T4 F4 G4 /make T5 from T5 G5 H5 /make T6 from T6 H6 I6 /make T7 from T7 I7 J7 /make T8 from T8 J8 K8 /make T9 from T9 K9 L9 /make U0 from U0 B0 C0 /make U1 from U1 C1 D1 /make U2 from U2 D2 E2 /make U3 from U3 E3 F3 /make U4 from U4 F4 G4 /make U5 from U5 G5 H5 /make U6 from U6 H6 I6 /make U7 from U7 I7 J7 /make U8 from U8 J8 K8 /make U9 from U9 K9 L9 /make V0 from V0 B0 C0 /make V1 from V1 C1 D1 /make V2 from V2 D2 E2 /make V3 from V3 E3 F3 /make V4 from V4 F4 G4 /make V5 from V5 G5 H5 /make V6 from V6 H6 I6 /make V7 from V7 I7 J7 /make V8 from V8 J8 K8 /make V9 from V9 K9 L9 /make W0 from W0 B0 C0 /make W1 from W1 C1 D1 /make W2 from W2 D2 E2 /make W3 from W3 E3 F3 /make W4 from W4 F4 G4 /make W5 from W5 G5 H5 /make W6 from W6 H6 I6 /make W7 from W7 I7 J7 /make W8 from W8 J8 K8 /make W9 from W9 K9 L9 /make X0 from X0 B0 C0 /make X1 from X1 C1 D1 /make X2 from X2 D2 E2 /make X3 from X3 E3 F3 /make X4 from X4 F4 G4 /make X5 from X5 G5 H5 /make X6 from X6 H6 I6 /make X7 from X7 I7 J7 /make X8 from X8 J8 K8 /make X9 from X9 K9 L9 /index = Index. Cheers!! 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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
Thanks Albert-Jan! But sorry I should have mentioned...the inputted list of variables for the parameter "vars" would not in reality index neatly from 1 to 5 or A to C. I used this as an example to illustrate the task at hand. Ideally, I'd like to keep the same format as the original macro - one parameter taking a list of variables and the other defining how many variable positions to step by in this list of variables to create each grouping for '/make' syntax line. Jignesh On Nov 23, 2011 7:16 PM, "Albert-Jan Roskam" <[hidden email]> wrote:
|
Administrator
|
In reply to this post by Jignesh Sutar
"I'd like to question whether this is some limitation in the use of DEFINE (and !DO loops within DEFINE) ".
Not that I am aware of! "or perhaps in the way I have coded the macro to achieve the desired result." More than likely! " If the latter (which would be my guess!), would there be a alternative way to code the macro to use less memory(?), loops(?) and simply be more efficient?" Probably so. Perhaps Post a sample invocation which hoses the process. Not going to stab at it in the dark.
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?" |
Administrator
|
Following up:
The following runs almost instantaneously (ver 11.5). DEFINE VAR2CASE (VARS !ENCLOSE("[","]") / DIV !TOKENS(1) ). !LET !TEMP="" !DO !V !IN (!VARS) !LET !TEMP=!CONCAT(!TEMP,"X") !DOEND !LET !NVARS=!LENGTH(!TEMP) !LET !SUB="" !DO !V= 1 !TO !NVARS !BY !DIV !LET !SUB=!CONCAT(!SUB,"X") !DOEND !LET !LENSUB=!LENGTH(!SUB) !LET !SYNTAX="VARSTOCASES " !LET !VARCOPY=!VARS !DO !I=1 !TO !DIV !LET !SYNTAX=!CONCAT(!SYNTAX,"/ MAKE VTOC_",!I, " FROM " ) !DO !J = 1 !TO !LENSUB !LET !SYNTAX=!CONCAT(!SYNTAX, !HEAD(!VARCOPY)," ")!LET !VARCOPY=!TAIL(!VARCOPY) !DOEND !DOEND !SYNTAX . !ENDDEFINE . SET MPRINT ON. *TEST DATA*. NEW FILE. INPUT PROGRAM. LOOP ID=1 TO 100. DO REPEAT V=V1 TO V500. COMPUTE V=NORMAL(1). END REPEAT. END CASE. END LOOP. END FILE. END INPUT PROGRAM. EXE. VAR2CASE VARS [v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35 v36 v37 v38 v39 v40 v41 v42 v43 v44 v45 v46 v47 v48 v49 v50 v51 v52 v53 v54 v55 v56 v57 v58 v59 v60 v61 v62 v63 v64 v65 v66 v67 v68 v69 v70 v71 v72 v73 v74 v75 v76 v77 v78 v79 v80 v81 v82 v83 v84 v85 v86 v87 v88 v89 v90 v91 v92 v93 v94 v95 v96 v97 v98 v99 v100 v101 v102 v103 v104 v105 v106 v107 v108 v109 v110 v111 v112 v113 v114 v115 v116 v117 v118 v119 v120 v121 v122 v123 v124 v125 v126 v127 v128 v129 v130 v131 v132 v133 v134 v135 v136 v137 v138 v139 v140 v141 v142 v143 v144 v145 v146 v147 v148 v149 v150 v151 v152 v153 v154 v155 v156 v157 v158 v159 v160 v161 v162 v163 v164 v165 v166 v167 v168 v169 v170 v171 v172 v173 v174 v175 v176 v177 v178 v179 v180 v181 v182 v183 v184 v185 v186 v187 v188 v189 v190 v191 v192 v193 v194 v195 v196 v197 v198 v199 v200 v201 v202 v203 v204 v205 v206 v207 v208 v209 v210 v211 v212 v213 v214 v215 v216 v217 v218 v219 v220 v221 v222 v223 v224 v225 v226 v227 v228 v229 v230 v231 v232 v233 v234 v235 v236 v237 v238 v239 v240 v241 v242 v243 v244 v245 v246 v247 v248 v249 v250 v251 v252 v253 v254 v255 v256 v257 v258 v259 v260 v261 v262 v263 v264 v265 v266 v267 v268 v269 v270 v271 v272 v273 v274 v275 v276 v277 v278 v279 v280 v281 v282 v283 v284 v285 v286 v287 v288 v289 v290 v291 v292 v293 v294 v295 v296 v297 v298 v299 v300 v301 v302 v303 v304 v305 v306 v307 v308 v309 v310 v311 v312 v313 v314 v315 v316 v317 v318 v319 v320 v321 v322 v323 v324 v325 v326 v327 v328 v329 v330 v331 v332 v333 v334 v335 v336 v337 v338 v339 v340 v341 v342 v343 v344 v345 v346 v347 v348 v349 v350 v351 v352 v353 v354 v355 v356 v357 v358 v359 v360 v361 v362 v363 v364 v365 v366 v367 v368 v369 v370 v371 v372 v373 v374 v375 v376 v377 v378 v379 v380 v381 v382 v383 v384 v385 v386 v387 v388 v389 v390 v391 v392 v393 v394 v395 v396 v397 v398 v399 v400 v401 v402 v403 v404 v405 v406 v407 v408 v409 v410 v411 v412 v413 v414 v415 v416 v417 v418 v419 v420 v421 v422 v423 v424 v425 v426 v427 v428 v429 v430 v431 v432 v433 v434 v435 v436 v437 v438 v439 v440 v441 v442 v443 v444 v445 v446 v447 v448 v449 v450 v451 v452 v453 v454 v455 v456 v457 v458 v459 v460 v461 v462 v463 v464 v465 v466 v467 v468 v469 v470 v471 v472 v473 v474 v475 v476 v477 v478 v479 v480 v481 v482 v483 v484 v485 v486 v487 v488 v489 v490 v491 v492 v493 v494 v495 v496 v497 v498 v499 v500] DIV 100. Generate Syntax: Syntax VARSTOCASES / MAKE VTOC_1 FROM v1 v2 v3 v4 v5 / MAKE VTOC_2 FROM v6 v7 v8 v9 v10 / MAKE VTOC_3 FROM v11 v12 v13 v14 v15 / MAKE VTOC_4 FROM v16 v17 v18 v19 v20 / MAKE VTOC_5 FROM v21 v22 v23 v24 v25 / MAKE VTOC_6 FROM v26 v27 v28 v29 v30 / MAKE VTOC_7 FROM v31 v32 v33 v34 v35 / MAKE VTOC_8 FROM v36 v37 v38 v39 v40 / MAKE VTOC_9 FROM v41 v42 v43 v44 v45 / MAKE VTOC_10 FROM v46 v47 v48 v49 v50 / MAKE VTOC_11 FROM v51 v52 v53 v54 v55 / MAKE VTOC_12 FROM v56 v57 v58 v59 v60 / MAKE VTOC_13 FROM v61 v62 v63 v64 v65 / MAKE VTOC_14 FROM v66 v67 v68 v69 v70 / MAKE VTOC_15 FROM v71 v72 v73 v74 v75 / MAKE VTOC_16 FROM v76 v77 v78 v79 v80 / MAKE VTOC_17 FROM v81 v82 v83 v84 v85 / MAKE VTOC_18 FROM v86 v87 v88 v89 v90 / MAKE VTOC_19 FROM v91 v92 v93 v94 v95 / MAKE VTOC_20 FROM v96 v97 v98 v99 v100 / MAKE VTOC_21 FROM v101 v102 v103 v104 v105 / MAKE VTOC_22 FROM v106 v107 v108 v109 v110 / MAKE VTOC_23 FROM v111 v112 v113 v114 v115 / MAKE VTOC_24 FROM v116 v117 v118 v119 v120 / MAKE VTOC_25 FROM v121 v122 v123 v124 v125 / MAKE VTOC_26 FROM v126 v127 v128 v129 v130 / MAKE VTOC_27 FROM v131 v132 v133 v134 v135 / MAKE VTOC_28 FROM v136 v137 v138 v139 v140 / MAKE VTOC_29 FROM v141 v142 v143 v144 v145 / MAKE VTOC_30 FROM v146 v147 v148 v149 v150 / MAKE VTOC_31 FROM v151 v152 v153 v154 v155 / MAKE VTOC_32 FROM v156 v157 v158 v159 v160 / MAKE VTOC_33 FROM v161 v162 v163 v164 v165 / MAKE VTOC_34 FROM v166 v167 v168 v169 v170 / MAKE VTOC_35 FROM v171 v172 v173 v174 v175 / MAKE VTOC_36 FROM v176 v177 v178 v179 v180 / MAKE VTOC_37 FROM v181 v182 v183 v184 v185 / MAKE VTOC_38 FROM v186 v187 v188 v189 v190 / MAKE VTOC_39 FROM v191 v192 v193 v194 v195 / MAKE VTOC_40 FROM v196 v197 v198 v199 v200 / MAKE VTOC_41 FROM v201 v202 v203 v204 v205 / MAKE VTOC_42 FROM v206 v207 v208 v209 v210 / MAKE VTOC_43 FROM v211 v212 v213 v214 v215 / MAKE VTOC_44 FROM v216 v217 v218 v219 v220 / MAKE VTOC_45 FROM v221 v222 v223 v224 v225 / MAKE VTOC_46 FROM v226 v227 v228 v229 v230 / MAKE VTOC_47 FROM v231 v232 v233 v234 v235 / MAKE VTOC_48 FROM v236 v237 v238 v239 v240 / MAKE VTOC_49 FROM v241 v242 v243 v244 v245 / MAKE VTOC_50 FROM v246 v247 v248 v249 v250 / MAKE VTOC_51 FROM v251 v252 v253 v254 v255 / MAKE VTOC_52 FROM v256 v257 v258 v259 v260 / MAKE VTOC_53 FROM v261 v262 v263 v264 v265 / MAKE VTOC_54 FROM v266 v267 v268 v269 v270 / MAKE VTOC_55 FROM v271 v272 v273 v274 v275 / MAKE VTOC_56 FROM v276 v277 v278 v279 v280 / MAKE VTOC_57 FROM v281 v282 v283 v284 v285 / MAKE VTOC_58 FROM v286 v287 v288 v289 v290 / MAKE VTOC_59 FROM v291 v292 v293 v294 v295 / MAKE VTOC_60 FROM v296 v297 v298 v299 v300 / MAKE VTOC_61 FROM v301 v302 v303 v304 v305 / MAKE VTOC_62 FROM v306 v307 v308 v309 v310 / MAKE VTOC_63 FROM v311 v312 v313 v314 v315 / MAKE VTOC_64 FROM v316 v317 v318 v319 v320 / MAKE VTOC_65 FROM v321 v322 v323 v324 v325 / MAKE VTOC_66 FROM v326 v327 v328 v329 v330 / MAKE VTOC_67 FROM v331 v332 v333 v334 v335 / MAKE VTOC_68 FROM v336 v337 v338 v339 v340 / MAKE VTOC_69 FROM v341 v342 v343 v344 v345 / MAKE VTOC_70 FROM v346 v347 v348 v349 v350 / MAKE VTOC_71 FROM v351 v352 v353 v354 v355 / MAKE VTOC_72 FROM v356 v357 v358 v359 v360 / MAKE VTOC_73 FROM v361 v362 v363 v364 v365 / MAKE VTOC_74 FROM v366 v367 v368 v369 v370 / MAKE VTOC_75 FROM v371 v372 v373 v374 v375 / MAKE VTOC_76 FROM v376 v377 v378 v379 v380 / MAKE VTOC_77 FROM v381 v382 v383 v384 v385 / MAKE VTOC_78 FROM v386 v387 v388 v389 v390 / MAKE VTOC_79 FROM v391 v392 v393 v394 v395 / MAKE VTOC_80 FROM v396 v397 v398 v399 v400 / MAKE VTOC_81 FROM v401 v402 v403 v404 v405 / MAKE VTOC_82 FROM v406 v407 v408 v409 v410 / MAKE VTOC_83 FROM v411 v412 v413 v414 v415 / MAKE VTOC_84 FROM v416 v417 v418 v419 v420 / MAKE VTOC_85 FROM v421 v422 v423 v424 v425 / MAKE VTOC_86 FROM v426 v427 v428 v429 v430 / MAKE VTOC_87 FROM v431 v432 v433 v434 v435 / MAKE VTOC_88 FROM v436 v437 v438 v439 v440 / MAKE VTOC_89 FROM v441 v442 v443 v444 v445 / MAKE VTOC_90 FROM v446 v447 v448 v449 v450 / MAKE VTOC_91 FROM v451 v452 v453 v454 v455 / MAKE VTOC_92 FROM v456 v457 v458 v459 v460 / MAKE VTOC_93 FROM v461 v462 v463 v464 v465 / MAKE VTOC_94 FROM v466 v467 v468 v469 v470 / MAKE VTOC_95 FROM v471 v472 v473 v474 v475 / MAKE VTOC_96 FROM v476 v477 v478 v479 v480 / MAKE VTOC_97 FROM v481 v482 v483 v484 v485 / MAKE VTOC_98 FROM v486 v487 v488 v489 v490 / MAKE VTOC_99 FROM v491 v492 v493 v494 v495 / MAKE VTOC_100 FROM v496 v497 v498 v499 v500 . Resources Elapsed Time 0:00:00.13
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?" |
Hi David, I actually need the macro to return the syntax as below and the only way I know how is how I originally coded it...? VARSTOCASES /MAKE VTOC_1 FROM v1 v101 v201 v301 v401
/MAKE VTOC_2 FROM v2 v102 v202 v302 v402 /MAKE VTOC_3 FROM v3 v103 v203 v303 v403
... /MAKE VTOC_98 FROM v98 v198 v298 v398 v498
/MAKE VTOC_99 FROM v99 v199 v299 v399 v499 /MAKE VTOC_100 FROM v100 v200 v300 v400 v500.
Cheers, Jignesh On 24 November 2011 02:10, David Marso <[hidden email]> wrote: Following up: |
In reply to this post by Jignesh Sutar
aah, I see. Then perhaps this will do the trick: import spss def varstocases(vlist, step=2, index="index"): varsL = vlist.split() cmd = ["/make %s from %s" % (varsL[i-step], " ".join(varsL[i-step:i])) for i in range(0, len(varsL)+1, step) if i > 0] spss.Submit("varstocases " + "\r\n ".join(cmd) + " /index=%s" % index) varstocases(vlist="var varx qwerty blah ughe zzz", step=2) This submits the following: varstocases /make var from var varx /make qwerty from qwerty blah /make ughe from ughe zzz /index=index Cheers!! 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? ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
You've fallen for the same trap as David! I would actually need it to return, from the example you've used: varstocases /make var from var qwerty ughe
/make varx from varx blah zzz /index=index. PS. I'm loving your choice of varaible names you've used in this example! And yes, that's more like to how my variables are likely to arrive! :) On 24 November 2011 14:22, Albert-Jan Roskam <[hidden email]> wrote:
|
Administrator
|
In reply to this post by Jignesh Sutar
See if this one floats your boat!
Basically using VECTOR and LOOPS to rederange the data ;-) Then using the same approach as previous. -- DEFINE VAR2CASE (VARS !ENCLOSE("[","]") / DIV !TOKENS(1) ). !LET !TEMP="" !DO !V !IN (!VARS) !LET !TEMP=!CONCAT(!TEMP,"X") !DOEND !LET !NVARS=!LENGTH(!TEMP) !LET !CVARS=!VARS !LET !NN="" !DO !V=2 !TO !NVARS !LET !NN=!CONCAT(!NN,"X") !DOEND !DO !I=1 !TO !LENGTH(!NN) !LET !CVARS=!TAIL(!CVARS) !DOEND !LET !SUB="" !DO !V= 1 !TO !NVARS !BY !DIV !LET !SUB=!CONCAT(!SUB,"X") !DOEND MATCH FILES / FILE * / KEEP !VARS. VECTOR V=!HEAD(!VARS) TO !CVARS / VC(!NVARS). COMPUTE #INDEX=1. LOOP #I=1 TO !DIV. + LOOP #J=0 TO !LENGTH(!SUB)-1. + COMPUTE VC(#INDEX)=V(#I + #J*!DIV). + COMPUTE #INDEX=#INDEX+1. + END LOOP. END LOOP. MATCH FILES / FILE * / DROP !VARS . RENAME VARIABLES (VC1 TO !CONCAT(VC,!NVARS)=!VARS). !LET !SYNTAX="VARSTOCASES " !LET !VARCOPY=!VARS !DO !I=1 !TO !DIV !LET !SYNTAX=!CONCAT(!SYNTAX,"/ MAKE VTOC_",!I, " FROM " ) !DO !J = 1 !TO !LENGTH(!SUB) !LET !SYNTAX=!CONCAT(!SYNTAX, !HEAD(!VARCOPY)," ")!LET !VARCOPY=!TAIL(!VARCOPY) !DOEND !DOEND !SYNTAX . !ENDDEFINE . SET MPRINT ON. *TEST DATA*. NEW FILE. INPUT PROGRAM. LOOP ID=1 TO 1000. DO REPEAT V=V1 TO V500 /VAL=1 TO 500. COMPUTE V=VAL. END REPEAT. END CASE. END LOOP. END FILE. END INPUT PROGRAM. EXE. VAR2CASE VARS [v1 v2 v3 v4 v5 v6 v7 v8 v9 v10 v11 v12 v13 v14 v15 v16 v17 v18 v19 v20 v21 v22 v23 v24 v25 v26 v27 v28 v29 v30 v31 v32 v33 v34 v35 v36 v37 v38 v39 v40 v41 v42 v43 v44 v45 v46 v47 v48 v49 v50 v51 v52 v53 v54 v55 v56 v57 v58 v59 v60 v61 v62 v63 v64 v65 v66 v67 v68 v69 v70 v71 v72 v73 v74 v75 v76 v77 v78 v79 v80 v81 v82 v83 v84 v85 v86 v87 v88 v89 v90 v91 v92 v93 v94 v95 v96 v97 v98 v99 v100 v101 v102 v103 v104 v105 v106 v107 v108 v109 v110 v111 v112 v113 v114 v115 v116 v117 v118 v119 v120 v121 v122 v123 v124 v125 v126 v127 v128 v129 v130 v131 v132 v133 v134 v135 v136 v137 v138 v139 v140 v141 v142 v143 v144 v145 v146 v147 v148 v149 v150 v151 v152 v153 v154 v155 v156 v157 v158 v159 v160 v161 v162 v163 v164 v165 v166 v167 v168 v169 v170 v171 v172 v173 v174 v175 v176 v177 v178 v179 v180 v181 v182 v183 v184 v185 v186 v187 v188 v189 v190 v191 v192 v193 v194 v195 v196 v197 v198 v199 v200 v201 v202 v203 v204 v205 v206 v207 v208 v209 v210 v211 v212 v213 v214 v215 v216 v217 v218 v219 v220 v221 v222 v223 v224 v225 v226 v227 v228 v229 v230 v231 v232 v233 v234 v235 v236 v237 v238 v239 v240 v241 v242 v243 v244 v245 v246 v247 v248 v249 v250 v251 v252 v253 v254 v255 v256 v257 v258 v259 v260 v261 v262 v263 v264 v265 v266 v267 v268 v269 v270 v271 v272 v273 v274 v275 v276 v277 v278 v279 v280 v281 v282 v283 v284 v285 v286 v287 v288 v289 v290 v291 v292 v293 v294 v295 v296 v297 v298 v299 v300 v301 v302 v303 v304 v305 v306 v307 v308 v309 v310 v311 v312 v313 v314 v315 v316 v317 v318 v319 v320 v321 v322 v323 v324 v325 v326 v327 v328 v329 v330 v331 v332 v333 v334 v335 v336 v337 v338 v339 v340 v341 v342 v343 v344 v345 v346 v347 v348 v349 v350 v351 v352 v353 v354 v355 v356 v357 v358 v359 v360 v361 v362 v363 v364 v365 v366 v367 v368 v369 v370 v371 v372 v373 v374 v375 v376 v377 v378 v379 v380 v381 v382 v383 v384 v385 v386 v387 v388 v389 v390 v391 v392 v393 v394 v395 v396 v397 v398 v399 v400 v401 v402 v403 v404 v405 v406 v407 v408 v409 v410 v411 v412 v413 v414 v415 v416 v417 v418 v419 v420 v421 v422 v423 v424 v425 v426 v427 v428 v429 v430 v431 v432 v433 v434 v435 v436 v437 v438 v439 v440 v441 v442 v443 v444 v445 v446 v447 v448 v449 v450 v451 v452 v453 v454 v455 v456 v457 v458 v459 v460 v461 v462 v463 v464 v465 v466 v467 v468 v469 v470 v471 v472 v473 v474 v475 v476 v477 v478 v479 v480 v481 v482 v483 v484 v485 v486 v487 v488 v489 v490 v491 v492 v493 v494 v495 v496 v497 v498 v499 v500] DIV 100. <quote author="J Sutar"> Hi David, I actually need the macro to return the syntax as below and the only way I know how is how I originally coded it...? VARSTOCASES /MAKE VTOC_1 FROM v1 v101 v201 v301 v401 /MAKE VTOC_2 FROM v2 v102 v202 v302 v402 /MAKE VTOC_3 FROM v3 v103 v203 v303 v403 ... /MAKE VTOC_98 FROM v98 v198 v298 v398 v498 /MAKE VTOC_99 FROM v99 v199 v299 v399 v499 /MAKE VTOC_100 FROM v100 v200 v300 v400 v500. Cheers, Jignesh <SNIP Previous >
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?" |
Free forum by Nabble | Edit this page |