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 (November 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 15 Nov 2006 06:27:20 -0500
Reply-To:     Jim Groeneveld <jim2stat@YAHOO.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jim Groeneveld <jim2stat@YAHOO.CO.UK>
Subject:      Re: counting the macro variables
Comments: To: Ankur Shanker <ankur.shanker@EVALUESERVE.COM>

Hi Ankur,

Suppose your macro is named Convert with arguments Dataset, VarName and NumCats, you can have a surrounding macro Surround as follows:

%MACRO Surround (Dataset=, VarList=, NcatList=); %* *untested*; %LOCAL I VarName NumCats; %LET I = 1; %LET VarName = %SCAN ( &VarList, &I, %STR( ) ); %* note the explicit single space between ( and ) after %STR; %DO %WHILE ( %LENGTH ( &VarName ) NE 0 ); %LET NumCats = %SCAN ( &NcatList, &I, %STR( ) ); %* Now calling your macro Convert; %Convert ( Dataset=&Dataset, VarName=&VarName, NumCats=&NumCats ); %LET I = %EVAL ( &I + 1 ); %LET VarName = %SCAN ( &VarList, &I, %STR( ) ); %END; %MEND Surround;

and call that macro as e.g.: %Surround ( Dataset=YourData, VarList=AgeCat Var1 Var4, NcatList=5 4 7 ); and take care the the number of variables equals the number of category amounts (as checks have not been built in).

Regards - Jim. -- Jim Groeneveld, Netherlands Statistician, SAS consultant home.hccnet.nl/jim.groeneveld

On Wed, 15 Nov 2006 05:14:35 -0500, Ankur Shanker <ankur.shanker@EVALUESERVE.COM> wrote:

>Hello Everyone! > >I have written a macro that converts the continuous variable into a >categorical variable. The macro is dynamic in the sense is all that it asks >for in the beginning are 1. the name of the dataset, 2. the variable name >and 3. the number of categories. The problem is that this macro works for >only one variable at a time. If I have ten variables to convert, then I >will have to input the values ten times. The macro that I want to write >should be such that in the beginning only I am able to specify the >variables to convert (one or more) and also the number of categories >corresponding to each variable. So, is there a way to achieve this? > >One thing that I am thinking of is: > >If there are 3 variables A, B & C then there is some macro that stores the >variable names as well as the number of variables,something like > >%macro pred_var(A,B,C); here, i want to store the values A, B & C and the >numeric 3. > >%macro pred_var(A,B,C,D,E); here, i'd like to store the values A, B, C, D & >E and the numeric 5. > >So, is there a way to do this? > >Thanks and regards, > >Ankur Shanker


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