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

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 1008 views
  • 4 likes
  • 4 in conversation