LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2007, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Sat, 7 Jul 2007 12:23:13 -0400
Reply-To:     Nathaniel.Wooding@DOM.COM
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Nat Wooding <Nathaniel.Wooding@DOM.COM>
Subject:      Re: Generating arrays
Comments: To: amritas2@AOL.COM
In-Reply-To:  <8C98E5A90601405-628-A666@WEBMAIL-MB01.sysops.aol.com>
Content-type: text/plain; charset=US-ASCII

Amrita

Here is one way to build your list.

Nat

Data one; input a b c d; cards; 1 2 3 4 5 6 7 8 Proc contents out=names (keep=name); Data _null_; set names end=eof ;

length string $ 200 ;* you may need for this to be much larger; retain string;

name=compress('T'||name); string=compbl(string||name); if eof then call symput('names',string);

run;

Data _null_; put "&names" ;* this just lets us see what we built. you would use "&names" in your array statement;

run;

Nat Wooding Environmental Specialist III Dominion, Environmental Biology 4111 Castlewood Rd Richmond, VA 23234 Phone:804-271-5313, Fax: 804-271-2977

Amrita Singh <amritas2@AOL.COM > To Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU Discussion" cc <SAS-L@LISTSERV.U GA.EDU> Subject Re: Generating arrays

07/06/2007 11:03 PM

Please respond to amritas2@AOL.COM

Hi,

I'm not sure why my posting was all messed up - probably the browser I'm using. I like your suggestion of using the second array to do the accumulations...that will work great. Now I just have to get over the hurdle of generating the second array definition which is based on the first array with a prefix. The reason being that I dont want to?manually affix the T_ in front of the hundreds of variables. I was looking for help with some macro code to do that.

Thanks for your help.

Amrita

-----Original Message----- From: Nathaniel.Wooding@dom.com To: amritas2@AOL.COM Cc: SAS-L@LISTSERV.UGA.EDU Sent: Fri, 6 Jul 2007 5:36 pm Subject: Re: Generating arrays

Amrita

When I received your posting, all of the color was gone and the text was a bit messed up. Try the following code and see how well it works for you. Note that I put in two arrays. The first you already had and that initializes the totals array. The second does the addition. I did this since if you have hundreds of variables, it will be easier to do the addition in the second array. The place where I would mess up if I were doing this would be in matching the elements in the two arrays -- sort of , if I had variables a and b, I would probably write the

array amts b a; array tamts a b;

which would not give the correct results.

Good luck

data rollin;

infile cards; input custnum dollars items; CARDS; 5 2 7 5 1 0 6 2 3 6 8 1 ; PRoc print; run;

Data Rollup; Set Rollin; by custnum; array amts(*) dollars items; array tamts(*) t_dollars t_items;

If first.custnum then do i = 1 to dim(tamts); tamts(i)=0; end;

do i = 1 to dim(tamts); tamts(i) + amts(i); end;

if last.custnum then output; keep custnum t: ; run; Proc Print; run;

Nat Wooding Environmental Specialist III Dominion, Environmental Biology 4111 Castlewood Rd Richmond, VA 23234 Phone:804-271-5313, Fax: 804-271-2977

Amrita Singh <amritas2@AOL.COM > To Sent by: "SAS(r) SAS-L@LISTSERV.UGA.EDU Discussion" cc <SAS-L@LISTSERV.U GA.EDU> Subject Re: Generating arrays

07/06/2007 05:10 PM

Please respond to amritas2@AOL.COM

Hi All,

Thanks so much for your responses. Unfortunately I cannot use PROC MEANS as Lou suggested because this code is only a small part of a data step that does a bunch of other stuff. So here is some?sample data and expected output as requested.?

?

data rollin;

infile cards;??????? input custnum dollars items;?

????????????????????????????????

CARDS;??????????????????????????

5 2 7???????????????????????????

5 1 0???????????????????????????

6 2 3???????????????????????????

6 8 1?????????????????????????

;?????????????????????????

Data Rollup; Set Rollin; by custnum; array amts(*) dollars items; array tamts(*) t_dollars t_items;

If first.custnum then? do; ???do i = 1 to dim(tamts); tamts(i)=0; end; end;

t_dollars + dollars t_items + items;

if last.custnum then output;

What I am?trying to do?is come up with?a macro that will generate the code to peform the parts highlighted in blue since there are hundreds of variables.?Any help would be greatly appreciated.

Thanks so much, Amrita

??????

-----Original Message----- From: Muthia Kachirayan <muthia.kachirayan@gmail.com> To: amritas2@aol.com Cc: SAS-L@listserv.uga.edu Sent: Thu, 5 Jul 2007 6:47 pm Subject: Re: Generating arrays

Amrita,

A sample data set and the required output will find you faster solution .

Muthia Kachirayan

On 7/5/07, Amrita Singh < amritas2@aol.com> wrote: Hi,

I have a situation where I have to accumulate hundreds of variables that are in an several arrays. Some arrays have 10 elements whereas other?arrays may have 80 elements.? ?? An?input array may look like this:

Array?inpvars (*) dollar6mo dollar12mo?items6mo?items12mo ..etc;

I have to generate an output array?which looks like this:

array outvars(*) t_dollar6mo t_dollar12mo?t_items6mo?t_items12mo ..etc

where the value of each output element is the accumulated value of the corresponding input element in a datastep with a first. and last.

for eg: ? t_dollar6mo?+ dollar6mo????? t_dollar12mo + dollar12mo...

I tried using the hbound function with symput to?get the number of elements from the input array and then use that to define the output array but had trouble with that. I also played with using vname to get the name of the array element and adding a prefix of t_ but ran into problems with that as well. I have a lot of data so I need to pass the file as few times as possible.

Any suggestions would be greatly appreciated!

Thanks, Amrita Singh ________________________________________________________________________ AOL now offers free email to everyone.??Find out more about what's free from AOL at AOL.com.

________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.

----------------------------------------- CONFIDENTIALITY NOTICE: This electronic message contains information which may be legally confidential and/or privileged and does not in any case represent a firm ENERGY COMMODITY bid or offer relating thereto which binds the sender without an additional express written confirmation to that effect. The information is intended solely for the individual or entity named above and access by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution, or use of the contents of this information is prohibited and may be unlawful. If you have received this electronic transmission in error, please reply immediately to the sender that you have received the message in error, and delete it. Thank you.

________________________________________________________________________ AOL now offers free email to everyone. Find out more about what's free from AOL at AOL.com.


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