Hi! I'm trying to use this macro, but I have a problem with the first "If" conditional, it's like SAS doesn't read the if, and jump all the marked part in the code. Could anyone please tell me what is wrong in the code? (The line 96 has the category Ingreso for the clase column)
Thanks in advance!
%macro recorre;
proc sql noprint;
SELECT count(*) INTO :total FROM WORK.DATA_DIA;
quit;
%Do I = 96 %to 96;
proc sql noprint;
SELECT tipo, clase, horanum INTO :n_tipo, :n_clase, :n_hora FROM WORK.DATA_DIA where n = &I;
quit;
%put &n_clase;
*Begin error;
%if &n_clase = 'Ingreso' %then %do;
%put 'ing';
%if &n_tipo = 'Demanda' %then %do;
%put 'dem';
%end;
%else %do;
%put 'ofe';
%end;
*End error;
%end; %put Fin; %End; %mend recorre; %recorre;
quick look tells me you don't need quotes around values in a macro statement
%macro recorre;
proc sql noprint;
SELECT count(*) INTO :total FROM WORK.DATA_DIA;
quit;
%Do I = 96 %to 96;
proc sql noprint;
SELECT tipo, clase, horanum INTO :n_tipo, :n_clase, :n_hora FROM WORK.DATA_DIA where n = &I;
quit;
%put &n_clase;
%if &n_clase = Ingreso %then %do;
%put 'ing';
%if &n_tipo = Demanda %then %do;
%put 'dem';
%end;
%else %do;
%put 'ofe';
%end;
%end;
%put Fin;
%End;
%mend recorre;
%recorre;
quick look tells me you don't need quotes around values in a macro statement
%macro recorre;
proc sql noprint;
SELECT count(*) INTO :total FROM WORK.DATA_DIA;
quit;
%Do I = 96 %to 96;
proc sql noprint;
SELECT tipo, clase, horanum INTO :n_tipo, :n_clase, :n_hora FROM WORK.DATA_DIA where n = &I;
quit;
%put &n_clase;
%if &n_clase = Ingreso %then %do;
%put 'ing';
%if &n_tipo = Demanda %then %do;
%put 'dem';
%end;
%else %do;
%put 'ofe';
%end;
%end;
%put Fin;
%End;
%mend recorre;
%recorre;
I meant for
%if &n_clase = 'Ingreso' %then %do;
%if &n_tipo = 'Demanda' %then %do;
Add the debugging options, run the macro again and review the log. If you still can’t get it working post the revised code and log.
Options mprint symbolgen mlogic;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.