BookmarkSubscribeRSS Feed
Gick
Pyrite | Level 9
%macro gick();
%let last= eat travel;
		%do l = 1 %to 2;
			proc freq data = dat_essai noprint;
			tables dates / out = compil;
			%if &l. = 1 %then /*The problem is in this line. It does not recognize &l. as a numeric value*/
                    %do;
				where I = 1 ;
			        %end;
			%if &l. = 2 %then
                    %do;
				where I >=3;
			        %end;
			run; 

			data compil;
			set compil;
			rename count = "%scan(&last.,&l.,' ')"n;
			keep dates count;
			run;

Hello,

 

When I run this code, I get this error message.
I saw this message in the forum and I tried to adjust, adapt my code to report the solutions I saw on the forum. But, it still does not work. I ask for a detailed explanation of what this problem is and how can I solve it.

Thank you for your help

 

Gickerror.PNG

34 REPLIES 34
PaigeMiller
Diamond | Level 26

If you open a brand new SAS session  and run this code, do you still get the error?

 

If so, please turn on the macro debugging options

 

options mprint symbolgen mlogic;

then run the code again.

 

Please show us the entire LOG for this macro (that's 100% of the log, every single line, not selected portions) by copying the log as text and pasting it into the window that appears when you click on the </> icon. 

 

Insert Log Icon in SAS Communities.png

--
Paige Miller
Gick
Pyrite | Level 9
Hello,

Here is the Log :

MLOGIC(gick) : %LET (le nom de la variable est LAST)
MLOGIC(gick) : %DBoucle DO démarrée ; variable indice L; valeur de départ : 1; valeur de fin : valeur de fin : 2;
valeur by : 1.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
&l. = 1
ERROR: The macro gick will stop executing.
MPRINT(gick): where I =
MLOGIC(gick) : Fin de l'exécution.
27
28 GOPTIONS NOACCESSIBLE;
29 %LET _CLIENTTASKLABEL=;
30 %LET _CLIENTPROCESSFLOWNAME=;
31 %LET _CLIENTPROJECTPATH=;
32 %LET _CLIENTPROJECTPATHHOST=;
33 %LET _CLIENTPROJECTNAME=;
34 %LET _SASPROGRAMFILE=;
WARNING: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation
marks.
35 %LET _SASPROGRAMFILEHOST=;
36
37 ;*';*";*/;quit;run;
38 ODS _ALL_ CLOSE;
39
40
41 QUIT; RUN;
Tom
Super User Tom
Super User

It is not a good idea to use both L and i as names of macro variables in the same program.

A lower case L looks a lot like an uppercase i .

 

Your %DO loop is using L.

Your %IF is using i.

 

Plus is looks a little strange that your dataset has a variable named i.  Make sure you are not getting confused and thinking that the macro variable i is the same thing as the dataset variable i.   

Gick
Pyrite | Level 9
Hello,
No , it is indeed L which is defined as a macro variable and I in capital letters is the name of the variable in the data set. I used it just in the Where statement
Tom
Super User Tom
Super User

In that case retype all of the white spaces to make sure you don't have binary zeros or other invisible characters in your program that you cannot detect in the error message.

Tom
Super User Tom
Super User

The only way I can get something like %IF &x = 1 %THEN to generate that error message is if the equal sign is not an equal sign.  That causes SAS to consider the whole string between %IF and %THEN as a single character expression instead of a comparison operator.

Kurt_Bremser
Super User

This WARNING:

WARNING: The quoted string currently being processed has become more than 262 characters long. You might have unbalanced quotation
marks.

can also be caused by submitting macro code without a %mend. The SAS system then keeps interpreting everything as further macro code, with all kinds of funny effects.

Whenever you encounter this message, terminate the current session and start with a new, clean one. Submit your code step by step until the message starts to appear, this will help you find the incorrect code part.

 

And, for the log to be really helpful to us, you MUST (as in MUST) use this button to post it:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

ballardw
Super User

You do not show a %mend statement to end the definition of the macro.

You do not show a matching %end for the %do l=1 %to 2 loop

 

You also do not show any call to that macro.

 

 

Note that use of code such as this, especially in a macro with loops,

data compil;
set compil;

is subject to all sorts of runtime value related errors and may mean the results are not what you think.

If the only purpose of a data step is to rename variables then use Proc Datasets. It will not change values if there is a hiccup and if the data set is large Proc Datasets will execute much faster as it only affects the data set header information where the variable names, formats, labels and such are stored. A data step has to process every record.

 

 

Gick
Pyrite | Level 9
Hello,

When copying the code, I forgot to copy %mend, %end. At this level there is no problem. Everything is in order. This is the error message that appears in the log, I find it difficult to understand because the code itself is well used in the macro.

I remain open to discussion.
Gick
Reeza
Super User
Would a format be more usable here than a macro?

proc format;
value I_fmt
1 = "eat"
3 - high = "travel"
other = 'exclude';
run;

proc freq data=dat_essai ...;
table I*dates / out=compil;
format l I_fmt.;
run;

Tom
Super User Tom
Super User

Either you have some strange character in your code that is confusing %IF.

Or there is something you aren't showing that is changing the value of the L macro variable.

 

Perhaps just re-typing the code will clear it up?

You could clean up the formatting and perhaps use more descriptive macro variable names while at it.  Make sure the define local macro variables as local.  It will not prevent macros you call from messing up their values but it will prevent this macro from messing up the values of macro variables that are being used by the code that is calling this macro.

 

%macro gick();
%local last index name where ;
%let last= eat travel;
%do index = 1 %to 2;
  %let name=%qscan(&last,&index,%str( ));
  %let name=%sysfunc(nliteral(&name));
  %if &index=1 then %let where=(I=1);
  %else %let where=(I>=3);

proc freq data = dat_essai ;
  where &where ;
  tables dates / noprint out=compil(drop=percent rename=(count=&name));
run; 

%end;
%mend gick;
Gick
Pyrite | Level 9
I adapted and adjusted your code in relation to what I'm looking for. I have the same error message
Tom
Super User Tom
Super User

Why bother using name literals if the list of names is just space delimited?  Are the names in the list not valid SAS names?  If they aren't then perhaps you should not be using space as the delimiter in the list of names since some of the names might contain spaces.  Also why are you asking %SCAN() to use both space and single quotes as the delimiter characters?  Are there really single quotes in the list of names? And if so did you really mean for them to be treated the same as the spaces when scanning?

Gick
Pyrite | Level 9
Hello,
In fact, the macro-variable "last" which has 2 words (eat, travel). The scan function returns the word to me according to the value of &L. and remove the blanks. For example %scan(&last.,1,' ')=eat, %scan(&last.,2,' ')=travel. At this level, there is no problem, the line operates normally.

It is the line %if &l=1 that I encounter a problem.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 34 replies
  • 2258 views
  • 1 like
  • 8 in conversation