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 ..

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 865 views
  • 1 like
  • 4 in conversation