LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous (more recent) messageNext (less recent) messagePrevious (more recent) in topicNext (less recent) in topicPrevious (more recent) by same authorNext (less recent) by same authorPrevious page (February 1996, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Thu, 15 Feb 1996 18:36:45 -0800
Reply-To:   Robin Way <robin@BCINC.COM>
Sender:   "SAS(r) Discussion" <SAS-L@UGA.CC.UGA.EDU>
From:   Robin Way <robin@BCINC.COM>
Organization:   Barakat & Chamberlin, Inc.
Subject:   Re: Array Problem in a Macro

Jim Stansell wrote: > <snip> > data temp; > %do t = 1 %to 5;

data tempfile; set temp; if survey ^= &t then delete;

proc means noprint data=tempfile; var q1 q2 q3; output out=index1 sum=s1 s2 s3; proc means noprint data=tempfile; var survey; output out=index2 n=nobs;

> > data index; > array result(5) v1-v5; > merge index1 index2 base; > result(&t) = (((s1+s2+s3) * (100 / nobs)) + 300) / base; > > %end; > ================================================ > <snip> > If I place the ARRAY statement in its current position, the variables > are re-initialized each time the loop executes, which wipes out the > previous calculations. > > On the other hand, if I place the ARRAY statement before the %DO > statement, I receive "Array Not Initialized" errors. > Jim: I'm going to propose you do this macro-based looping in two steps. The proc means steps can be combined into one step (either means or summary), which should be performed in a macro do loop much like you have already. Save the results from each proc in a new dataset that uses the value of &t as a suffix (the dataset name _and_ the var names). Then merge all of them in the final dataset, and run another macro do loop just after the merge statement and ending before the end of the dataset--make sure to use the run; statement at the end of the dataset--after resolving the 2nd macro. I assume from your previous code that you want to have a sum of vars q1-q3 and a count of the number of obs that is specific to meeting the criterion of survey=&t. If not, I apologize for inferring incorrectly. Also I'm afraid I haven't tested this, but call me if there's bugs. Try something like this:

%macro loop; %do t = 1 %to 5; proc summary data=temp (where survey=&t); var q1 q2 q3 survey; output out=index&t sum(q1)=s1&t sum(q2)=s2&t sum(q3)=s3&t n=nobs&t; run; %end; * t loop; data index; array result (5) v1-v5; merge index1 index2 index3 index4 index5; *all have 1 obs each; %do j = 1 %to 5; result(&j) = (((s1&j + s2&j + s3&j) * (100 / nobs&j)) + 300) / base; %end; * j loop; run; %mend loop; %loop

Robin Way Barakat & Chamberlin, Inc. Portland, Oregon robin@bcinc.com


Back to: Top of message | Previous page | Main SAS-L page