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 (October 2004, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 20 Oct 2004 17:39:42 +0800
Reply-To:   KUMAR Arun <KUMARA@ESSILOR.COM.SG>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   KUMAR Arun <KUMARA@ESSILOR.COM.SG>
Subject:   Re: accesing a variable from calling data statement inside a call ed macro
Comments:   To: Megha <mvkokane@KANBAY.COM>
Content-Type:   text/plain

Hi Megha, I just changed the approach based on my understanding of the problem. There were some logical/syntax problems with your codes. I tested the codes with two test datasets. Let me know whether it suits your requirements or if there is any query.

data bin_map_dataset; input range category $; cards; 10 A 20 B 30 C ; run; data Acct_avg_freq1; acct_freq=5; output; acct_freq=5; output; acct_freq=25; output; run;

%macro aa; data _NULL_ ; set bin_map_dataset nobs=nobs end=eof; call symput('range'||trim(left(_n_)), trim(left(range))); call symput('category'||trim(left(_n_)), trim(left(category))); if eof then call symput('nobs', trim(left(nobs))); run;

%put _user_;

data Acct ; set Acct_avg_freq1; call symput('acct_freq',Acct_freq); retain ll 0;

%do j=1 %to &nobs; %if &j > 1 %then %do; else %end;

if ll < Acct_freq <= &&range&j then do; Acct_freq_bin = "&&category&j"; lower_limit = &&range&j; end; %end; run;

%mend aa; %aa

Regards Arun

-----Original Message----- From: Megha [mailto:mvkokane@KANBAY.COM] Sent: Wednesday, October 20, 2004 2:01 PM To: SAS-L@LISTSERV.UGA.EDU Subject: accesing a variable from calling data statement inside a called macro

Hello. I am a newbie in SAS. I am trying to write a macro to implement binning of any variable passed to it as a parameter and put the category(ie the bin value) in another variable name which is also passed as a parameter. The range of values of the variable to be binned and the corresponding category is given in a dataset bin_map_dataset.

Following is the code I tried:

%macro bin_macro(varname, bin_varname); data _NULL_ ; set bin_map_dataset; retain lower_limit 0; if lower_limit < &varname <= range then &bin_varname = category; lower_limit = range; run; %mend;

data Acct_avg_freq1 ; set Acct_avg_freq1; %bin_macro(Acct_freq, Acct_freq_bin); run;

Here Acct_freq is the variable to be binned and Acct_freq_bin is the new column created in the Acct_avg_freq1 dataset which will contain the corresponding category accrording to the value of Acct_freq. The bin_map_dataset is something like as follows: 10 A 20 B 30 C ........and so on This says that if 0 < Acct_freq <= 10, then category is Acct_freq_bin = 'A'.

When I run this code, the variable Acct_freq is not recognized inside the macro. The error message is : Variable Acct_freq is uninitialized.

Actually the variable name Acct_freq passed to the macro literally as a text, and the numeric value of this variable is not passed.

Also can you tell me how I can I make some SAS array global and accessible inside a macro? Or how can I declare a macro variable which is an array?

I will be really very thankful to you if you help me solve my doubts. Thanks in advance. Regards. Megha Kokane, Kanbay e-solutions, Pune, India


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