BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
Newlifewithegg
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-
from sashelp.cars
where Cylinders ne .;
quit;

%put &=SQLOBS;

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


%allcylinders

 

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

SQLOBS=7

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:
%SQLOBS
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.
1 ACCEPTED SOLUTION

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

 

should say

 

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

View solution in original post

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

 

should say

 

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

and also, 

title "&&val%i-Cylinder Cars";
needs to be 
title "&&val&i-Cylinder Cars";
Tom
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.

Newlifewithegg
Calcite | Level 5

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

Newlifewithegg
Calcite | Level 5

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

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 5 replies
  • 1377 views
  • 1 like
  • 4 in conversation