jeudi 14 juin 2018

SAS %If else macro

I have problem with simply macro %IF %ELSE. I have to set switch "Y" or "N" (more in the future) where this variable runs differents part of code. Example:

data REKORD_RACH;
   input id_wsadu dept $;
   datalines;
1 Sales
2 Acctng
3 eeeaa
4 ffff
;
%LET Czy_Max = 'Y';
OPTION MPRINT;
option compress=yes validvarname=any;

%macro Set_id_wsadu(Czy_Max);
   %if &Czy_Max. = 'N' %then
      %do;
        %let id_wsadu = 3;/*Tu wpisujemy ręcznie id wsadu które nas interesuje*/
    %end;

   %else %if &Czy_Max. = 'Y' %then
      %do;
            Proc SQL NOPRINT;
            Select MAX(id_wsadu) Into :id_wsadu
            From Work.REKORD_RACH;
            quit;
      %end;
%mend;
%Set_id_wsadu;

%put &id_wsadu;

PROC SQL;
   CREATE TABLE REKORD_RACH_GET AS 
   SELECT *
   FROM REKORD_RACH
   WHERE ID_WSADU = &id_wsadu
;QUIT;

But Sas guide shows me these log:

54         %mend;
55         %Set_id_wsadu;
56         
57         %put &id_wsadu;
WARNING: Apparent symbolic reference ID_WSADU not resolved.
&id_wsadu

What I should do to make it work?

Aucun commentaire:

Enregistrer un commentaire