|
> 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
|