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 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 19 Oct 2010 15:38:04 -0400
Reply-To:     Chang Chung <chang_y_chung@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Chang Chung <chang_y_chung@HOTMAIL.COM>
Subject:      Re: getting an %superq evaluation to work in a macro fired by
              another macro
Comments: To: Svend White <SvendW@HEALTH.OK.GOV>

On Tue, 19 Oct 2010 13:48:28 -0500, White, Svend A. <SvendW@HEALTH.OK.GOV> wrote:

>I'm trying to clean up a macro to make it easier to read and manage. One >section has a long series of code blocks like this: > > %if %superq(adm_t_s)= %then %do; > %let adm_t_s=ALL; > %let adm_t_s0=0; > %let adm_t_s1=ALL; > %end; > %else %if %superq(adm_t_s0)= %then %do; > %let adm_t_s0=1; > %let adm_t_s1=%superq(adm_t_s); > %end; > %if %superq(dischStatus)= %then %do; > %let dischStatus=ALL; > %let dischStatus0=0; > %let dischStatus1=ALL; > %end; > %else %if %superq(dischStatus0)= %then %do; > %let dischStatus0=1; > %let dischStatus1=%superq(dischStatus); > %end; > >I'd like to replace that redundant code with a macro something along >these lines: > >%populatevarsformultiselectlist(varname=adm_t_s); >%populatevarsformultiselectlist(varname=dischStatus); > > >Here's my current version of the macro: > >%macro populatevarsformultiselectlist(varname=) ; > > %local varname0 varname1; > %let varname0=&varname.0; > %let varname1=&varname.1; > %put "*** varname0 is &varname0"; > %put "*** varname1 is &varname1"; > > %if %superq(varname)= %then %do; > %put "***varname is null"; > %let &varname=ALL; > %let &varname0=0; > %let &varname1=ALL; > %end; > %else %if %superq(varname0)= %then %do; > %put "***varname0 is null"; > %let &varname0=1; > %let &varname1=%superq(varname); > %end; > >%mend populatevarsformultiselectlist; > >Currently, those evaluations of &varname and &varname0 are failing >(i.e., false when they should be true). > >Do I need to parse the variable names somehow in the %superq functions >for this to work properly?

Hi,

Well,... if the varname has nothing in it, then &varname resolves to nothing at all. so your macro becomes strange as below, and I don't think you want this: ... %let varname0 = 0; %let varname1 = 1; ... %if %superq(varname)= %then %do; %*-- true --*; %let =ALL; %let 0=0; %let 1=ALL; ...

I think you meant something more like below. Hope this helps a bit.

Cheers, Chang

%macro pop(name=);

%if %superq(name)= %then %return; %*-- needs name --*;

%local var0 var1; %let var0 = &name.0; %let var1 = &name.1;

%local &var0 &var1;

%if %superq(&name)= %then %do; %*-- blank --*; %let &name = blank; %let &var0 = blank; %let &var1 = blank; %end; %else %do; %*-- non-blank --*; %let &name = non-blank; %let &var0 = non-blank; %let &var1 = non-blank; %end;

%put _user_; %*-- notice that &name is global --*; %mend pop;

%*-- check. blank --*; %symdel adm_t_s adm_t_s0; %let adm_t_s=; %pop(name=adm_t_s) %*-- on log, in part POP ADM_T_S1 blank POP ADM_T_S0 blank GLOBAL ADM_T_S blank --*;

%*-- check. non-blank --*; %let adm_t_s=ABC; %pop(name=adm_t_s) %*-- on log, in part POP ADM_T_S1 non-blank POP ADM_T_S0 non-blank GLOBAL ADM_T_S non-blank --*;


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