%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
Gick
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.
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.
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.
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.
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:
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.
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;
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?
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.