Loop and macro help

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Loop and macro help

Laura Leach
Hi, Below is the syntax that I am trying to automate because it needs to be
done several hundred times.  I am new to SPSS and feel like I am currently
killing an ant with a slede-hammer by doing this by hand.  The entire point
of this syntax is to get the value of "Base1E1_DEL" for every case.  But to
arrive at that, in the DO IF, "qA4=1" is related to the variable
label "Base1" (i.e., qA4=10 label equals Base10, etc.) and the "qC1=1" is
related to the "E1" part of the label (no systematic link because label
part is alphanumeric).  These two variables qA4 and qC1 do not change in a
systematic way (i.e., they are not 1,2,3,4, etc.).  What I have been doing
is copying and pasting this piece of syntax for every single iteration.
(qA4 has 90 different values, and qC1 has 5 different values).  Is there a
way to streamline this to change the values of qA4/qC1 and it's
corresponding new variable label, or even better yet, is there a way to
arrive at the _DEL vairable without creating 4 new variables to get there?

Thanks for any help!!
Laura




DO IF (qA4=1 AND qC1=1) .
COUNT  Base1E1_FAV = qE1a qE1b qE1c (5 thru 6)  .
END IF .
EXECUTE .

DO IF (qA4=1 AND qC1=1).
COUNT  Base1E1_TOL = qE1a qE1b qE1c (1 thru 6)  .
END IF.
EXECUTE .

COMPUTE Base1E1_PFAV = Base1E1_FAV / Base1E1_TOL .
EXECUTE .

COMPUTE Base1E1_DEL = Base1E1_PFAV-AFFav.
EXECUTE .
Reply | Threaded
Open this post in threaded view
|

Re: Loop and macro help

Albert-Jan Roskam
Hi Laura,

Below is something you could try. I had a hard time
understanding what exactly you wanted to do. Since
you've made some syntax already, you could compare the
outcome of my syntax with the one you made yourself.
You should really make that comparison, as I am REALLY
not sure about this solution (maybe it's the wine I
drank earlier *hick-up* ;-))

Btw, please be aware that COUNT counts the events
(e.g. '5 thru 6'). This means that 'non-events' are in
this example '1' BUT ALSO missing values! This is
something which yours truly discovered much too late.
;-)

loop #i = 1 to 90.
loop #j = 1 to 5.
do if (qA4=#i and qC1=#j) .
count  Base1E1_FAV = qE1a qE1b qE1c (5 thru 6)  .
count Base1E1_TOL = qE1a qE1b qE1c (1 thru 6)  .
end if.
end loop.
end loop.
compute Base1E1_DEL = (Base1E1_FAV / Base1E1_TOL)  -

  AFFav.
exe.

Cheers!
Albert-Jan


--- Laura Leach <[hidden email]> wrote:

> Hi, Below is the syntax that I am trying to automate
> because it needs to be
> done several hundred times.  I am new to SPSS and
> feel like I am currently
> killing an ant with a slede-hammer by doing this by
> hand.  The entire point
> of this syntax is to get the value of "Base1E1_DEL"
> for every case.  But to
> arrive at that, in the DO IF, "qA4=1" is related to
> the variable
> label "Base1" (i.e., qA4=10 label equals Base10,
> etc.) and the "qC1=1" is
> related to the "E1" part of the label (no systematic
> link because label
> part is alphanumeric).  These two variables qA4 and
> qC1 do not change in a
> systematic way (i.e., they are not 1,2,3,4, etc.).
> What I have been doing
> is copying and pasting this piece of syntax for
> every single iteration.
> (qA4 has 90 different values, and qC1 has 5
> different values).  Is there a
> way to streamline this to change the values of
> qA4/qC1 and it's
> corresponding new variable label, or even better
> yet, is there a way to
> arrive at the _DEL vairable without creating 4 new
> variables to get there?
>
> Thanks for any help!!
> Laura
>
>
>
>
> DO IF (qA4=1 AND qC1=1) .
> COUNT  Base1E1_FAV = qE1a qE1b qE1c (5 thru 6)  .
> END IF .
> EXECUTE .
>
> DO IF (qA4=1 AND qC1=1).
> COUNT  Base1E1_TOL = qE1a qE1b qE1c (1 thru 6)  .
> END IF.
> EXECUTE .
>
> COMPUTE Base1E1_PFAV = Base1E1_FAV / Base1E1_TOL .
> EXECUTE .
>
> COMPUTE Base1E1_DEL = Base1E1_PFAV-AFFav.
> EXECUTE .
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: Loop and macro help

Laura Leach
In reply to this post by Laura Leach
Hi,
Thank you for this code.  I'm beginning to understand what I need to do,
although this syntax didn't work exactly right. Let me add a little
explaination and see if this makes sense.  qA4 is a place, given a numeric
value, but the values don't go in continuous order (e.g., place =
1,2,4,5,6,8,10, etc.) because some places have been omitted from this
analysis.  Since I need a Base[Place #]_DEL for every qA4, then what you
have below doesn't work.  qC1 is simply, 1,2,3,4,5.  Can I alter the first
line to be "loop #i = 1 2 4 5. " and keep line 2, or will that not work?
And if that does work to loop through with defined values rather than
continuous, how do I get a different output variable for each iteration of
the loop?  (i.e., Base#i#j_DEL)  Thank you so much for your help!

Laura



>
>loop #i = 1 to 90.
>loop #j = 1 to 5.
>do if (qA4=#i and qC1=#j) .
>count  Base1E1_FAV = qE1a qE1b qE1c (5 thru 6)  .
>count Base1E1_TOL = qE1a qE1b qE1c (1 thru 6)  .
>end if.
>end loop.
>end loop.
>compute Base1E1_DEL = (Base1E1_FAV / Base1E1_TOL)  -
>
>  AFFav.
>exe.
>
Reply | Threaded
Open this post in threaded view
|

Re: Loop and macro help

Albert-Jan Roskam
Hi,

It's hard for me to test it without the actual data.
The various Base#i#j_DEL format variables require a
different approach. Maybe it's also possible with
VECTOR, I don't know, but I choose a macro approach.

As far as I know, a LOOP index requires a adjacent
values, i.e. 1 to 15 and not 1 5 6 8 10 or something
like that. In SAS the format 1 to 3 6 to 9 is also
accepted, I believe. DO REPEAT does not have this
requirement.

* macro.
set mprint = on.

define laura (series = !cmdend).

do repeat #i = !series.
  !do !j = 1 !to 5.
     do if (qA4=#i and qC1=!j) .
       count  Base1E1_FAV = qE1a qE1b qE1c (5 thru 6)
.
       count Base1E1_TOL = qE1a qE1b qE1c (1 thru 6)
.
     end if.
     !let !i_j = !concat('Base',#i,'E',!j,'_').
     compute !concat(!i_j,'DEL') =
(!concat(!i_j,'FAV') / !concat(!i_j,'TOL'))  - AFFav.
  !doend.
end repeat print.

exe.

!enddefine.

* macro call.
* under 'series' you should specify the non-adjacent
series of qA4.
laura series = 1 2 4 5 6 8 10 12 18 40 60 78 85 90.


*******.

define laura (series = !cmdend).

do repeat #i = !series.
  !do !j = 1 !to 5.
     do if (age=#i and educ=!j) .
       count  Base1E1_FAV = paeduc maeduc speduc (5
thru 6)  .
       count Base1E1_TOL = paeduc maeduc speduc (1
thru 6)  .
     end if.
     !let !i_j = !concat('Base',#i,'E',!j,'_').
     ** compute !concat(!i_j,'DEL') =
(!concat(!i_j,'FAV') / !concat(!i_j,'TOL'))  - AFFav.
  !doend.
end repeat print.

exe.

!enddefine.

*****.

GET
  FILE='C:\Program Files\SPSSEval\1991 U.S. General
Social Survey.sav'.

laura series = 1 2 4 5 6 8 10 12 18 40 60 78 85 90.


laura series = 1 2 4 5 6 8 10 12 18 40 60 78 85 90.
  66 M>
  67 M>  .
  68 M>  do repeat #i = 1 2 4 5 6 8 10 12 18 40 60 78
85 90.
  69 M>
  70 M>  do if (age=#i and educ= 1 ).
  71 M>  count Base1E1_FAV = paeduc maeduc speduc (5
thru 6).
  72 M>  count Base1E1_TOL = paeduc maeduc speduc (1
thru 6).
  73 M>  end if.
  74 M>
  75 M>
  76 M>  do if (age=#i and educ= 2 ).
  77 M>  count Base1E1_FAV = paeduc maeduc speduc (5
thru 6).
  78 M>  count Base1E1_TOL = paeduc maeduc speduc (1
thru 6).
  79 M>  end if.
  80 M>
  81 M>
  82 M>  do if (age=#i and educ= 3 ).
  83 M>  count Base1E1_FAV = paeduc maeduc speduc (5
thru 6).
  84 M>  count Base1E1_TOL = paeduc maeduc speduc (1
thru 6).
  85 M>  end if.
  86 M>
  87 M>
  88 M>  do if (age=#i and educ= 4 ).
  89 M>  count Base1E1_FAV = paeduc maeduc speduc (5
thru 6).
  90 M>  count Base1E1_TOL = paeduc maeduc speduc (1
thru 6).
  91 M>  end if.
  92 M>
  93 M>
  94 M>  do if (age=#i and educ= 5 ).
  95 M>  count Base1E1_FAV = paeduc maeduc speduc (5
thru 6).
  96 M>  count Base1E1_TOL = paeduc maeduc speduc (1
thru 6).
  97 M>  end if.
  98 M>
  99 M>
 100 M>  end repeat print.

 100 +do if          (age=1 and educ= 1 )
 101 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 102 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 103 +end if
 104 +do if          (age=1 and educ= 2 )
 105 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 106 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 107 +end if
 108 +do if          (age=1 and educ= 3 )
 109 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 110 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 111 +end if
 112 +do if          (age=1 and educ= 4 )
 113 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 114 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 115 +end if
 116 +do if          (age=1 and educ= 5 )
 117 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 118 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 119 +end if
 120 +do if          (age=2 and educ= 1 )
 121 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 122 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 123 +end if
 124 +do if          (age=2 and educ= 2 )
 125 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 126 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 127 +end if
 128 +do if          (age=2 and educ= 3 )
 129 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 130 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 131 +end if
 132 +do if          (age=2 and educ= 4 )
 133 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 134 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 135 +end if
 136 +do if          (age=2 and educ= 5 )
 137 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 138 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 139 +end if
 140 +do if          (age=4 and educ= 1 )
 141 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 142 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 143 +end if
 144 +do if          (age=4 and educ= 2 )
 145 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 146 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 147 +end if
 148 +do if          (age=4 and educ= 3 )
 149 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 150 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 151 +end if
 152 +do if          (age=4 and educ= 4 )
 153 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 154 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 155 +end if
 156 +do if          (age=4 and educ= 5 )
 157 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 158 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 159 +end if
 160 +do if          (age=5 and educ= 1 )
 161 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 162 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 163 +end if
 164 +do if          (age=5 and educ= 2 )
 165 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 166 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 167 +end if
 168 +do if          (age=5 and educ= 3 )
 169 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 170 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 171 +end if
 172 +do if          (age=5 and educ= 4 )
 173 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 174 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 175 +end if
 176 +do if          (age=5 and educ= 5 )
 177 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 178 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 179 +end if
 180 +do if          (age=6 and educ= 1 )
 181 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 182 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 183 +end if
 184 +do if          (age=6 and educ= 2 )
 185 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 186 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 187 +end if
 188 +do if          (age=6 and educ= 3 )
 189 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 190 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 191 +end if
 192 +do if          (age=6 and educ= 4 )
 193 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 194 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 195 +end if
 196 +do if          (age=6 and educ= 5 )
 197 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 198 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 199 +end if
 200 +do if          (age=8 and educ= 1 )
 201 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 202 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 203 +end if
 204 +do if          (age=8 and educ= 2 )
 205 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 206 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 207 +end if
 208 +do if          (age=8 and educ= 3 )
 209 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 210 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 211 +end if
 212 +do if          (age=8 and educ= 4 )
 213 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 214 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 215 +end if
 216 +do if          (age=8 and educ= 5 )
 217 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 218 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 219 +end if
 220 +do if          (age=10 and educ= 1 )
 221 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 222 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 223 +end if
 224 +do if          (age=10 and educ= 2 )
 225 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 226 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 227 +end if
 228 +do if          (age=10 and educ= 3 )
 229 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 230 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 231 +end if
 232 +do if          (age=10 and educ= 4 )
 233 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 234 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 235 +end if
 236 +do if          (age=10 and educ= 5 )
 237 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 238 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 239 +end if
 240 +do if          (age=12 and educ= 1 )
 241 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 242 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 243 +end if
 244 +do if          (age=12 and educ= 2 )
 245 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 246 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 247 +end if
 248 +do if          (age=12 and educ= 3 )
 249 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 250 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 251 +end if
 252 +do if          (age=12 and educ= 4 )
 253 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 254 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 255 +end if
 256 +do if          (age=12 and educ= 5 )
 257 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 258 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 259 +end if
 260 +do if          (age=18 and educ= 1 )
 261 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 262 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 263 +end if
 264 +do if          (age=18 and educ= 2 )
 265 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 266 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 267 +end if
 268 +do if          (age=18 and educ= 3 )
 269 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 270 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 271 +end if
 272 +do if          (age=18 and educ= 4 )
 273 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 274 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 275 +end if
 276 +do if          (age=18 and educ= 5 )
 277 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 278 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 279 +end if
 280 +do if          (age=40 and educ= 1 )
 281 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 282 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 283 +end if
 284 +do if          (age=40 and educ= 2 )
 285 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 286 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 287 +end if
 288 +do if          (age=40 and educ= 3 )
 289 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 290 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 291 +end if
 292 +do if          (age=40 and educ= 4 )
 293 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 294 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 295 +end if
 296 +do if          (age=40 and educ= 5 )
 297 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 298 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 299 +end if
 300 +do if          (age=60 and educ= 1 )
 301 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 302 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 303 +end if
 304 +do if          (age=60 and educ= 2 )
 305 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 306 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 307 +end if
 308 +do if          (age=60 and educ= 3 )
 309 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 310 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 311 +end if
 312 +do if          (age=60 and educ= 4 )
 313 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 314 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 315 +end if
 316 +do if          (age=60 and educ= 5 )
 317 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 318 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 319 +end if
 320 +do if          (age=78 and educ= 1 )
 321 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 322 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 323 +end if
 324 +do if          (age=78 and educ= 2 )
 325 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 326 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 327 +end if
 328 +do if          (age=78 and educ= 3 )
 329 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 330 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 331 +end if
 332 +do if          (age=78 and educ= 4 )
 333 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 334 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 335 +end if
 336 +do if          (age=78 and educ= 5 )
 337 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 338 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 339 +end if
 340 +do if          (age=85 and educ= 1 )
 341 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 342 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 343 +end if
 344 +do if          (age=85 and educ= 2 )
 345 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 346 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 347 +end if
 348 +do if          (age=85 and educ= 3 )
 349 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 350 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 351 +end if
 352 +do if          (age=85 and educ= 4 )
 353 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 354 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 355 +end if
 356 +do if          (age=85 and educ= 5 )
 357 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 358 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 359 +end if
 360 +do if          (age=90 and educ= 1 )
 361 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 362 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 363 +end if
 364 +do if          (age=90 and educ= 2 )
 365 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 366 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 367 +end if
 368 +do if          (age=90 and educ= 3 )
 369 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 370 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 371 +end if
 372 +do if          (age=90 and educ= 4 )
 373 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 374 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 375 +end if
 376 +do if          (age=90 and educ= 5 )
 377 +count          Base1E1_FAV = paeduc maeduc
speduc (5 thru 6)
 378 +count          Base1E1_TOL = paeduc maeduc
speduc (1 thru 6)
 379 +end if

 381 M>  exe
 382 M>  .


--- Laura Leach <[hidden email]> wrote:

> Hi,
> Thank you for this code.  I'm beginning to
> understand what I need to do,
> although this syntax didn't work exactly right. Let
> me add a little
> explaination and see if this makes sense.  qA4 is a
> place, given a numeric
> value, but the values don't go in continuous order
> (e.g., place =
> 1,2,4,5,6,8,10, etc.) because some places have been
> omitted from this
> analysis.  Since I need a Base[Place #]_DEL for
> every qA4, then what you
> have below doesn't work.  qC1 is simply, 1,2,3,4,5.
> Can I alter the first
> line to be "loop #i = 1 2 4 5. " and keep line 2, or
> will that not work?
> And if that does work to loop through with defined
> values rather than
> continuous, how do I get a different output variable
> for each iteration of
> the loop?  (i.e., Base#i#j_DEL)  Thank you so much
> for your help!
>
> Laura
>
>
>
> >
> >loop #i = 1 to 90.
> >loop #j = 1 to 5.
> >do if (qA4=#i and qC1=#j) .
> >count  Base1E1_FAV = qE1a qE1b qE1c (5 thru 6)  .
> >count Base1E1_TOL = qE1a qE1b qE1c (1 thru 6)  .
> >end if.
> >end loop.
> >end loop.
> >compute Base1E1_DEL = (Base1E1_FAV / Base1E1_TOL)
> -
> >
> >  AFFav.
> >exe.
> >
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Reply | Threaded
Open this post in threaded view
|

Re: Loop and macro help (2)

Albert-Jan Roskam
In reply to this post by Laura Leach
Sorry, I accidentally hit "send".
The second chunk of code is modified so it can be
tested (e.g. syntactical correctness) using the sample
data file '1991 U.S. General Social Survey.sav'.
Note that I didn't test the COMPUTE.

Hope this works, or that you now can make it work.

Albert-Jan



--- Laura Leach <[hidden email]> wrote:

> Hi,
> Thank you for this code.  I'm beginning to
> understand what I need to do,
> although this syntax didn't work exactly right. Let
> me add a little
> explaination and see if this makes sense.  qA4 is a
> place, given a numeric
> value, but the values don't go in continuous order
> (e.g., place =
> 1,2,4,5,6,8,10, etc.) because some places have been
> omitted from this
> analysis.  Since I need a Base[Place #]_DEL for
> every qA4, then what you
> have below doesn't work.  qC1 is simply, 1,2,3,4,5.
> Can I alter the first
> line to be "loop #i = 1 2 4 5. " and keep line 2, or
> will that not work?
> And if that does work to loop through with defined
> values rather than
> continuous, how do I get a different output variable
> for each iteration of
> the loop?  (i.e., Base#i#j_DEL)  Thank you so much
> for your help!
>
> Laura
>
>
>
> >
> >loop #i = 1 to 90.
> >loop #j = 1 to 5.
> >do if (qA4=#i and qC1=#j) .
> >count  Base1E1_FAV = qE1a qE1b qE1c (5 thru 6)  .
> >count Base1E1_TOL = qE1a qE1b qE1c (1 thru 6)  .
> >end if.
> >end loop.
> >end loop.
> >compute Base1E1_DEL = (Base1E1_FAV / Base1E1_TOL)
> -
> >
> >  AFFav.
> >exe.
> >
>


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com