A MACRO HELP NEEDED - I am new in Macro (please help me)

A MACRO HELP NEEDED - I am new in Macro (please help me)

Post by need_sas_h » Wed, 21 May 2008 05:45:10


I have a sample code as below:


%Macro select (AgB, CAB);


if &AgB = '1' then AgB = "Aucun sympt^ome";
else if &AgB = "2" then AgB = "Atteinea";
else if &AgB = "3" then AgB = "Atteineb";
else if &AgB = "4" then AgB = "Atteinec";
else if &AgB = "p" then AgB = "Atteined";
else if &AgB = "q" then AgB = "Atteinee";
else if &AgB = "z" then AgB = "Atteinef";
if &CAB = '1' then CAB = "Aucun sympt^ome";
else if &CAB = "2" then CAB = "Atteinea";
else if &CAB = "3" then CAB = "Atteineb";
else if &CAB = "4" then CAB = "Atteinec";
else if &CAB = "p" then CAB = "Atteined";
else if &CAB = "q" then CAB = "Atteinee";
else if &CAB = "z" then CAB = "Atteinef";
run;

%Mend select;
%select (Choutri, Passenger)
run;






Now there is a repitation of the same group of statements or group of
codes twice ( actually
in the original program there is hundreds time repitaion). How can I put
those
repeted statements or codes in a Macro? The program already has a Macro
select.
 
 
 

A MACRO HELP NEEDED - I am new in Macro (please help me)

Post by rjf2 » Wed, 21 May 2008 06:01:18

you need data step help
not macro help

Proc Format library = Library;
value $AbB '1' = 'Aucun sympt^ome'
'2' = 'Atteinea'
'3' = 'Atteineb'
'4' = 'Atteinec'
'p' = 'Atteined'
'q' = 'Atteinee'
'z' = 'Atteinef'
other = 'Invalid';

in data step:
%Let AgB = Choutri;

&AgB. = put(AgB,$AgB.);

similarly for CAB.

value $CAB '1' =
...
'z' =
other = 'Invalid';

%Let CAB = Passenger;

&CAB. = put(CAB,$CAB.);


This principle is known variously as:

* reduction of wall-paper code

* put the data in the look-up table
-- here the proc format value statement --
rather than in the program

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

 
 
 

A MACRO HELP NEEDED - I am new in Macro (please help me)

Post by hs AT dc-s » Wed, 21 May 2008 08:22:14

o need for a macro. No need for a format, though it is good practice in
this situation; if you do opt for the format approach, only one is required.

What is needed, with or without a format, is a DO loop and arrays. Demo:

data have;
input Choutri $ Passenger $;
cards;
p 3
4 1
;

data need(drop=pointer);
set have;
array short(2) Choutri Passenger;
array long (2) $ 15 AgB CAB;
do pointer = 1 to 2;
if short(pointer) = '1' then long(pointer) = "Aucun sympt^ome";
else if short(pointer) = "2" then long(pointer) = "Atteinea";
else if short(pointer) = "3" then long(pointer) = "Atteineb";
else if short(pointer) = "4" then long(pointer) = "Atteinec";
else if short(pointer) = "p" then long(pointer) = "Atteined";
else if short(pointer) = "q" then long(pointer) = "Atteinee";
else if short(pointer) = "z" then long(pointer) = "Atteinef";
end;
run;

Result:

Choutri Passenger AgB CAB

p 3 Atteined Atteineb
4 1 Atteinec Aucun sympt^ome

On Mon, 19 May 2008 17:01:18 -0400, Fehd, Ronald J. (CDC/CCHIS/NCPHI)
< XXXX@XXXXX.COM > wrote: