BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fri0
Quartz | Level 8

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;
 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

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;

View solution in original post

6 REPLIES 6
novinosrin
Tourmaline | Level 20

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;
fri0
Quartz | Level 8
Hi! if you said it for the words 'ing', 'dem' and 'ofe', it's just to probe the code. But I couldn't get those prints.
novinosrin
Tourmaline | Level 20

I meant for 

 

	%if &n_clase = 'Ingreso' %then %do;
		
		%if &n_tipo = 'Demanda' %then %do;
fri0
Quartz | Level 8
It totally works! Thanks you very much!
Satish_Parida
Lapis Lazuli | Level 10
This is a very common mistake,
We confuse the string comparison in data step if and macro %if.
As mentioned above, the string do not need to be in quote for comparison. Also you do not need to have quotes around strings to %put.
Everything in macro is already character.
Reeza
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1056 views
  • 4 likes
  • 4 in conversation