Dear SPSSX-L Listers,
I have a SAS file to run a frequency and reach analysis that I am trying to recreate into SPSS. However, I am very rusty in SAS and I am not sure how to recreate some of the commands in SPSS. Help would be extremely appreciated. Partial SAS code is printed below. Where I am having the most trouble is with the "IF THEN" statements. Mainly because of the {bskcnt} and {a} statements. also, the SAS code goes on and on with the else if statements for &bsk=n and I figure there would be some way to loop it to make it more efficient. However, that is beyond my experience. again.. any and all help is greatly appreciated. ================================ %MACRO CHOC(fl,bsk); data b; infile indat lrecl=10 recfm=v missover; input @1 (input1-input10) (1.); run; data c; set b; array input{12} input1-input12; array reach{1000} reach1-reach1000; array fqcy{1000} fqcy1-fqcy1000; if &bsk=1 then do; bskcnt=0; do a=1 to &fl; bskcnt=bskcnt+1; fqcy{bskcnt}=input{a}; if fqcy{bskcnt} ge 1 then reach{bskcnt}=1; else reach{bskcnt}=0; if fqcy{bskcnt}=0 then fqcy{bskcnt}=.; end; end; else if &bsk=2 then do; bskcnt=0; do a=1 to &fl; bcnt=a+1; do b=bcnt to &fl; bskcnt=bskcnt+1; fqcy{bskcnt}=input{a}+input{b}; if fqcy{bskcnt} ge 1 then reach{bskcnt}=1; else reach{bskcnt}=0; if fqcy{bskcnt}=0 then fqcy{bskcnt}=.; end; end; end; else if &bsk=3 then do; bskcnt=0; do a=1 to &fl; bcnt=a+1; do b=bcnt to &fl; ccnt=b+1; do c=ccnt to &fl; bskcnt=bskcnt+1; fqcy{bskcnt}=input{a}+input{b}+input{c}; if fqcy{bskcnt} ge 1 then reach{bskcnt}=1; else reach{bskcnt}=0; if fqcy{bskcnt}=0 then fqcy{bskcnt}=.; end; end; end; end; |
At 07:23 PM 9/11/2006, Eddy Crane wrote:
>I have a SAS file to run a frequency and reach analysis that I am >trying to recreate into SPSS. > >Where I am having the most trouble is with the "IF THEN" statements. >Mainly because of the {bskcnt} and {a} statements. also, the SAS code >goes on and on with the else if statements for &bsk=n and I figure >there would be some way to loop it to make it more efficient. The {bskcnt} and {a} are array references, with 'bskcnt' and 'a' as the indices. Your code seems to mark, in array or vector 'reach', all combinations of &bsk elements from &fl inputs for which any of the elements has a non-zero value. I've translated the SAS to SPSS for &bsk=3. You could write it without a separate block for each value of &bsk, but it means reworking the logic. I'm not going to do that, at least not unless you say more of what this is about. The result looks clumsy to use, as it stands. I've changed the SAS code to SPSS comments, and followed them by the equivalent SPSS. The SPSS code is not tested. * The code has been 'unwrapped' from a SAS macro, whose only working . * content seems to be the MACRO statement itself: . * * %MACRO CHOC(fl,bsk); * * In the SPSS code, macro parameters &fl and &bsk have been replaced . * by SPSS variables @f1 and @bsk. . * THIS CODE WILL NOT BE TESTED, OR RUN IN ANY WAY . * Only the block for &bsk=3 is translated. . *SAS data b; --- . *SAS infile indat lrecl=10 recfm=v missover; --- . *SAS input @1 (input1-input10) (1.); --- . . DATA LIST FILE=indat FIXED /input1 TO input10 (10F1). *SAS run; --- . *=== Irrelevant; equivalent to SPSS's EXECUTE . *SAS data c; --- . *SAS set b; --- . *=== Relevant only if you want to keep input dataset b unchanged for . *=== future use. If you do, . . DATASET COPY b /* SPSS 14 and later */. *=== or . . SAVE OUTFILE=b. /* SPSS 13 and earlier */ *SAS array input{12} input1-input12; --- . . NUMERIC input11 input12 (F1). . VECTOR input=input1 TO input10. *--- Remark: You have input1 TO input10 in your input. I've --- . * declared input11 and input 12. --- . * The VECTOR works only if input1-input12 are contiguous in --- . * the file. If this declaration doesn't make them --- . * contiguous, you can declare all 12 contiguous in an --- . * INPUT PROGRAM, then readonly the first 10. --- . *SAS array reach{1000} reach1-reach1000; --- . . VECTOR reach(1000,F3). *SAS array fqcy{1000} fqcy1-fqcy1000; --- . . VECTOR fqcy(1000,F3). <code for &bsk=1 and &bsk=2 omitted> *SAS else if &bsk=3 then do; --- . . ELSE IF @BSK EQ 3. *SAS bskcnt=0; --- . . COMPUTE bskcnt = 0. *SAS do a=1 to &fl; --- . . LOOP a=1 TO @f1. *SASb bcnt=a+1; --- . *SAS do b=bcnt to &fl; --- . *=== Either . . COMPUTE bcnt = a+1. . LOOP b = bcnt TO @f1. *=== or . * LOOP b = a+1 TO @f1. *SASb ccnt=b+1; --- . *SAS do c=ccnt to &fl; --- . *=== Either . . COMPUTE ccnt=b+1 . LOOP c = ccnt TO @f1. *=== or . . LOOP c = b+1 TO @f1 . *SAS bskcnt=bskcnt+1; --- . . COMPUTE bskcnt = bskcnt+1. *--- Remark: so 'bskcnt' counts total loop iterations . *SAS fqcy{bskcnt}=input{a}+input{b}+input{c}; --- . . COMPUTE fqcy(bskcnt) = input(a)+input(b)+input(c). *--- Remark: The a/b/c nested loop adds all --- . *--- possible triples of different values from --- . *--- the inputs, and stores each in its own array --- . *--- element ('vector element' in SPSS). --- . *SAS if fqcy{bskcnt} ge 1 then reach{bskcnt}=1; --- . *SASb else reach{bskcnt}=0; --- . *SAS if fqcy{bskcnt}=0 then fqcy{bskcnt}=.; --- . *--- Question: Are the numbers in array 'fqcy' --- . *--- ever used again? If not, there's no reason --- . *--- it need by an array; a scalar would do fine. --- . *SAS end /* loop c */; --- . . END LOOP /* c */. *SAS end /* loop b */; --- . . END LOOP /* b */. *SAS end /* loop a */; --- . . END LOOP /* a *. *SAS end; --- . *=== Omit in SPSS, if an ELSE IF or ELSE follows. --- . *=== If it's the last clause, then --- . . END IF. |
Free forum by Nabble | Edit this page |