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 2006, week 4)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Mon, 24 Jul 2006 16:26:36 -0400
Reply-To:     Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Subject:      Re: Storing the values of a variable in a Macro variable

Ankur

your need is basic simple SAS

define array of all variables indexed from 75 to (188+75 -1) array vars{ 75 : 262 } var75 - var262; * use array ; sum = sum( of vars(1) - vars(n) ) ; * basic use of array element resolving at run time ;

unfortunately that sum statement is not valid syntax, because such array elements stntax is not valid for end-points of a variable name list, because the list must be defined at compile time, and your N varies by observation.

So, it seems there is nothing for it, but simple loop, like: sum = 0; do i= lbound( vars) to n ; sum = sum( sum, vars(i) ); end;

Why would you want a macro solution ?

Peter

P.S. Would Data Analytics of eValueServe like to hire some SAS help ? ... ... ... or buy some training ???

On Tue, 25 Jul 2006 01:20:26 +0530, Ankur Shanker <ankur.shanker@EVALUESERVE.COM> wrote:

>Hi, > >To make the problem specific, this is what I am trying to achieve. > >For example, > >If Free_Duration=5 then sum=var75+ var76+ var77+ var78+ var79; >If Free_Duration=2 then sum=var75+ var76; > >And so on.. > >i.e. the sum should start from the variable var75 and thereon >sequentially depending on the value of Free_duration. > >/**************************/ > >%macro abcd; > >sum=0; >%do i=1 %to &n. %by 1; > > >nextvar=&i.+74; >call symput('m',nextvar); >sum=sum+var&m.; > >%end; > >%mend abcd; > > >data test4; >set test3; >call symput('n',Free_Duration); >%abcd; >run; > >/**************************/ > >I hope I have made the problem amply clear. > >Thanks and regards, > >Ankur Shanker > >________________________________ > >Business Analyst, Data Analytics >Evalueserve >Tel: +91 124 415 4600 (ext: 4488) >Fax: +91 124 406 3430 >www.evalueserve.com > > > > > >-----Original Message----- >From: toby dunn [mailto:tobydunn@hotmail.com] >Sent: Tuesday, July 25, 2006 12:58 AM >To: Ankur Shanker; SAS-L@LISTSERV.UGA.EDU >Subject: RE: Storing the values of a variable in a Macro variable > >Ankur , > >Uhh perhaps a macro is even needed. But to determine that we would need >to >see yoru code and a bigger overview of what you want to accomplish. > >Barring a clearer and braoder explaination consider this: > >Data _Null_ ; >Set <something> ; > >call symput('n',Free_duration); >Run ; > >Will overwrite the macro variable 'n''s value with each iteration of the > >data step. Now you could just as easily do the following: > > >Data _Null_ ; >Set <something> ; > >call symput( Compress( 'N' || Put( _N_ , 8. -L ) ) , Free_duration ) ; >Run ; > >Which will create a new macro variable with each iteration of the data >step. > But that means you will end up with some large number of global macro >variables sitting out there and you will need to police them. Also to >use >them you will need to at the least create yet another macro variable >which >will keep track of how many you have. > >Data _Null_ ; >Set <something> Nobs = Nobs End = EOF ; > >call symput( Compress( 'N' || Put( _N_ , 8. -L ) ) , Put( Free_duration >, 8. >-L ) ) ; > >IF EOF then Call SYmput( 'NumOfMVars' , Put( NOBS , 8. -L ) ) ; >Run ; > > > >Then you have to worrie what happens when you accidently delete one of >these >or you over write the value, etc..... the headaches just get worse. >Like I >said let us know what you need to do and we can help you get there >perhaps >without macros. > > > >Toby Dunn > >'They say that Spanish is the Language of Love, >I Loved the way it rolled off of her tongue' > >'I dont know what she said but I loved the way she said it' > > > > > > >From: Ankur Shanker <ankur.shanker@EVALUESERVE.COM> >Reply-To: Ankur Shanker <ankur.shanker@EVALUESERVE.COM> >To: SAS-L@LISTSERV.UGA.EDU >Subject: Storing the values of a variable in a Macro variable >Date: Mon, 24 Jul 2006 15:15:17 -0400 > >HI, > >I have to run a macro which will take different values from a numeric >variable Free_duration. As the number of observations is very large, I >want to store those numeric values in a macro variable, which will then >automatically execute the macro and this is the code that I am trying to >make work.. > >call symput('n',Free_duration); > >But the problem is that it's not working. > >Can you please try and help on this. > >Thanks in advance. > >Ankur Shanker > > > > >DISCLAIMER: >The information in this e-mail is the property of Evalueserve and is confidential and privileged. It is intended solely for the addressee. Access to this email by anyone else is unauthorized. If you are not the intended recipient, any disclosure, copying, distribution or any action taken in reliance on it is prohibited and will be unlawful. If you receive this message in error, please notify the sender immediately and delete all copies of this message.


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