BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Calcite | Level 5

I am using the online sas studio.


The code is as follows,


%macro allcylinders;
proc sql noprint;
select distinct Cylinders
into :val1-
where Cylinders ne .;

%put &=SQLOBS;

%do i=1 %to %SQLOBS;
title "&&val%i-Cylinder Cars";
proc print noobs;
var Make Model Type Origin MSRP MPG_City MPG_Highway;
where Cylinders=&&val&i;
%mend allcylinders;



The macro compilation passes successfully. When I run the macro, it complains the following,


WARNING: Apparent invocation of macro SQLOBS not resolved.
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was:
ERROR: The %TO value of the %DO I loop is invalid.
But as I printed on the screen, the macro variable SQLOBS=7, thus I don't understand why it issues the specific WARNING, and then give the next ERROR message.

Accepted Solutions
Diamond | Level 26
%do i=1 %to %SQLOBS;


should say


%do i=1 %to &SQLOBS;
Paige Miller

View solution in original post

Diamond | Level 26
%do i=1 %to %SQLOBS;


should say


%do i=1 %to &SQLOBS;
Paige Miller
Lapis Lazuli | Level 10

and also, 

title "&&val%i-Cylinder Cars";
needs to be 
title "&&val&i-Cylinder Cars";
Super User Tom
Super User

There are two trigger characters that the macro processor looks for to decide if it should intervene.


The & is used for referencing macro variables (aka SYMBOLS).

The % is used for macro statements, functions and user defined macros.


You tried to call a macro named SQLOBS instead of reference the value of a macro variable named SQLOBS.

Calcite | Level 5

Thank all for your help! Feel so ashamed to have made so stupid mistakes ...

Calcite | Level 5

sorry, don't know how to accept more than one solution ..


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
  • 5 replies
  • 1 like
  • 4 in conversation