Date: Mon, 23 Mar 2009 04:19:47 -0400
Reply-To: Søren Lassen <s.lassen@POST.TELE.DK>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Søren Lassen <s.lassen@POST.TELE.DK>
Subject: Re: Do Loop: Insert Macro Value row by row
Content-Type: text/plain; charset=ISO-8859-1
Sounds like something that is more easily accomplished in SQL.
I would suggest trying something like:
proc sql;
%do i=1 %to 10;
insert into final (<list variable names>)
select
sum(<variable>) as <name>, /* same as PROC SUMMARY produces */
sum(<variable>) as <name>,
mean(<variable>) as <name>,
.
.
count(*) as _FREQ_,
<macrovar 1 value> as M1,
<macrovar 2 value> as M2
from <whatever> where <whatever>
;
%end;
quit;
Regards,
Søren
On Sun, 22 Mar 2009 07:26:50 -0500, OR Stats <stats112@GMAIL.COM> wrote:
>Thanks all for your reply. I ended up using the following in case it may
be
>faster(?):
>
>%do i = 1 to 10;
>
>*create summary info;
>proc summary data = stuff;
> output out=temp;
>run;
>
>*add in macro variables;
>%let macrovar1=...;
>%let macrovar2=...;
>
>*Merge summary and macro info;
>data temp;
> set temp;
> m1=¯ovar1;
> m2=¯ovar2;
>run;
>
>*append the results;
>data final;
> set final temp;
>run;
>
>%end;
>
>Any comments on which types of steps run faster in SAS would be good
>discussions too. Cheers
>
>On Sat, Mar 21, 2009 at 11:21 PM, Andy Bowden <andybowden@gmail.com>
wrote:
>
>> On Mar 22, 11:42 am, stats...@GMAIL.COM (OR Stats) wrote:
>> > ???
>> >
>> > There is a proc summary step that generates a single row output to
which
>> I
>> > append to an existing dataset final. The macrovariables is a
function of
>> > step _i_ of the loop. The actual variable names etc. is not really
>> > relevant, no?
>> >
>> > On Sat, Mar 21, 2009 at 5:37 PM, Jay <CarolinaJa...@gmail.com> wrote:
>> > > On Mar 21, 4:13 pm, stats...@GMAIL.COM (OR Stats) wrote:
>> > > > Hello:
>> >
>> > > > I have a Do Loop that I run that appends values to an existing
Data
>> table
>> > > > row by row:
>> >
>> > > > %do i=1 %to 10;
>> > > > /*steps here that creates temp*/
>> > > > PROC SUMMARY data=....
>> > > > output out=temp;
>> > > > RUN;
>> > > > DATA final;
>> > > > set final temp;
>> > > > RUN;
>> > > > %let macrovar1=...;
>> > > > %let macrovar2=...;
>> > > > %end;
>> >
>> > > > How do I insert my macrovar1 & macrovar2 recalculated at each
>> iteration
>> > > into
>> > > > my dataset final? The following did not work,
>> > > > DATA final;
>> > > > set final temp;
>> > > > M1=¯ovar1;
>> > > > M2=¯ovar2;
>> > > > RUN;
>> >
>> > > > This didn't work b.c. M1 and M2 columns were just the macrovar1
and
>> > > > macrovar2 at the last step. And this also did not work
>> > > > DATA store;
>> > > > M1=¯ovar1;
>> > > > M2=¯ovar2;
>> > > > RUN;
>> > > > DATA final;
>> > > > set final temp store;
>> > > > RUN;
>> >
>> > > > This didn't work, because at each step i, two rows are created
>> instead of
>> > > > one (i.e., one new row from new proc summary step and another new
row
>> > > from
>> > > > data store step). Ideally, at each step i, only one row is added
to
>> > > final;
>> > > > the variables of these rows are that found in the PROC SUMMARY
output
>> > > table
>> > > > and the updated macrovariables macrovar1 and macrovar2.
>> >
>> > > > Would greatly appreciate your help...thanx!!
>>
>>
>> Hi,
>>
>> This is a method to get your second attempt at the code to do what you
>> need. It wont be the most elegant way of doing it, but should get your
>> single row appended to the final dataset that you were after.
>>
>> %do i = 1 to 10;
>>
>> *create summary info;
>> proc summary data = stuff;
>> output out=temp;
>> run;
>>
>> *add in macro variables;
>> data store;
>> m1=¯ovar1;
>> m2=¯ovar2;
>> run;
>>
>> *Merge summary and macro info;
>> data sum_and_macro;
>> set temp;
>> set store;
>> run;
>>
>> *append the results;
>> proc append base=final data=sum_and_macro;
>> run;
>>
>> %end;
>>
>> Apologies if there are any syntax issues, I haven't got SAS installed
>> here.
>>
>> Hope this helps,
>>
>> Andy.
>>
|