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 (March 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:   Wed, 17 Mar 2010 17:03:39 -0400
Reply-To:   "Fehd, Ronald J. (CDC/OSELS/NCPHI)" <rjf2@CDC.GOV>
Sender:   "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:   "Fehd, Ronald J. (CDC/OSELS/NCPHI)" <rjf2@CDC.GOV>
Subject:   Re: SAS Macro - Is there a way to use an if statement to set two variables?
In-Reply-To:   <3f92be0a-cefb-4ba6-9dc1-f8c424b11116@r1g2000yqj.googlegroups.com>
Content-Type:   text/plain; charset=us-ascii

> From: Mieds > Sent: Wednesday, March 17, 2010 3:19 PM > To: sas-l@uga.edu > Subject: SAS Macro - Is there a way to use an if statement to set two > variables? > > Hi, > > I'm new to SAS and would like to write a macro that loops through a > number of times and can set two variables based on an if statement. I > am wondering if this is possible, or if I have to use two if > statements, one for each variable. > > Thanks in advance for any suggestions. > > For example, > > %MACRO CreateTables (CatNums); > > %do n=1 %to &CatNums; > %if &n=1 %then %let catname=One and %let > catnumber=1; > %else %if &n=2 %then %let catname=Two and %let > catnumber=2; > > PROC SQL; > CREATE TABLE Category&CatName AS > SELECT * > FROM Data AS T1 > WHERE T1.category = &CatNumber > QUIT; > > %end; > %MEND CreateTables;

AND is a logical connector, not an instruction

%if &n=1 %then %do; %let catname=One; %let catnumber=1; %end; %else %if &n=2 %then %do; %let catname=Two; %let catnumber=2; %end;

you could save a couple of instructions:

%do catnumber = 1 %to &CatNums; %if &catnumber = 1 %then %let catname=One; %else %if &catnumber = 2 %then %let catname=Two; *...; %end;

Ron Fehd the macro maven CDC Atlanta GA USA RJF2 at cdc dot gov


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