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 (April 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 17 Apr 2007 14:20:28 -0400
Reply-To:     Jake Bee <johbee@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Jake Bee <johbee@GMAIL.COM>
Subject:      Re: What's wrong with this macro?
Comments: To: "Elmaache, Hamani" <Hamani.Elmaache1@cra-arc.gc.ca>
In-Reply-To:  <82FD85BED187814D8BB11E7DFE35098D24F8E7@sh0cx691.prod.net>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

You may just may be a little confused as to which way to look at the problem. So two examples are given to illustrate at least 2 views. But unless this is an exercise to build a more complex macro a macro is not needed here. Regardless, testing the different views is useful.

dm 'out' clear; dm 'log' clear;

options symbolgen mprint;

data a; length id $4 sex $1; id='1001'; sex='F'; output; id='1002'; sex='M'; output; run;

%macro makeds_ex1(ds=, male=male_ds, female=female_ds); data &female &male; set &ds; if sex='F' then output &female; else output &male; run; %mend makeds_ex1;

%makeds_ex1(ds=a);

%macro xmakeds_ex2(ds=,gender=);

%local out_ds;

%if &gender eq F %then %do; %let out_ds=female; %end; %else %do; %let out_ds=male; %end;

data &out_ds; set &ds; %if &gender eq M %then %do; if sex='M'; %end; %else %do; if sex='F'; %end;

output &out_ds;

run;

%mend xmakeds_ex2;

%xmakeds_ex2(ds=a, gender=M); %xmakeds_ex2(ds=a, gender=F);

On 4/17/07, Elmaache, Hamani <Hamani.Elmaache1@cra-arc.gc.ca> wrote: > > Thank you very much SAS users. > I did: > Change %if to if, %then to then, and %else to else > > It works, but it doesn't work whith these %if and %then and %else. > > > > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] > Sent: April 17, 2007 12:24 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: What's wrong with this macro? > > > Change %if to if, %then to then, and %else to else. Other than that, it > is difficult to see any other problem without seeing your call to the > macro. > > Cliff > > -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of > Elmaache, Hamani > Sent: Tuesday, April 17, 2007 12:12 PM > To: SAS-L@LISTSERV.UGA.EDU > Subject: What's wrong with this macro? > > Can someone run this macro and tells me hat's wrong with it? > > Thanks a lot. > > > options symbolgen mprint; > %macro makeds(ds=, male=, female=); > data &female &male; > set &ds ; > %if sex='F' %then output &female ; > %else output &male ; > run; > %mend makeds; > > ---------------------------------------------------------------------- > LEGAL NOTICE > Unless expressly stated otherwise, this message is confidential and may be > privileged. It is intended for the addressee(s) only. Access to this > E-mail by anyone else is unauthorized. If you are not an addressee, any > disclosure or copying of the contents of this E-mail or any action taken (or > not taken) in reliance on it is unauthorized and may be unlawful. If you > are not an addressee, please inform the sender immediately. >


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