Stu
Stu

Reputation: 1643

Can't get this SAS macro right, need advice

Here is the macro below, along with an example at the bottom. When I try to run this I get many errors, and I think it has something to do with the way I am using if-else statements. The example should return "Gum and Other Mouth". Thanks!

        %Macro CancerSite(PrimSite, Hist);
            * Site recoding: http://seer.cancer.gov/siterecode/icdo3_d01272003/ (old version since cases in years < 2010);
            Histology = input(&Hist, 4.);
            PrimarySite = &PrimSite;

            * Oral Cavity and Pharynx;
            if Histology not in (9050:9055, 9140, 9590:9992) then do;
                if PrimarySite in ('C000','C001','C002','C003','C004','C005','C006','C007','C008','C009')
                    then CancerSite = 'Lip';
                else if PrimarySite in ('C030','C031','C032','C033','C034','C035','C036','C037','C038','C039',
                    'C050','C051','C052','C053','C054','C055','C056','C057','C058','C059',
                    'C060','C061','C062','C063','C064','C065','C066','C067','C068','C069')
                    then CancerSite = 'Gum and Other Mouth';
                else if PrimarySite in ('C110','C111','C112','C113','C114','C115','C116','C117','C118','C119')
                    then CancerSite = 'Nasopharynx';
                else if PrimarySite in ('C090','C091','C092','C093','C094','C095','C096','C097','C098','C099')
                    then CancerSite = 'Tonsil';
            end;
        %mend;

%CancerSite('C030', 9057)

Upvotes: 0

Views: 65

Answers (1)

user667489
user667489

Reputation: 9569

If you run this as is and in isolation, it will construct a bunch of data step statements but without the rest of the data step - you need to call the macro in the middle of a data step for it to work properly.

E.g.

data output_dataset;
  set input_dataset;
  %CancerSite('C030', 9057)
run;

Upvotes: 4

Related Questions