I am currently studying macro variables course. When I did the practice question with SAS Studio, whenever I submit a code with macro variable, it failed and generated the same code as following. Could you please help me to figure it out? I am super anxious about this trouble!
Looks like you are missing a %MEND statement at the end of your macro.
PLEASE Please please post log entries by copying the text from the log and pasting into a code window opened with the forum's </> icon. This should even be easier than creating an image file and uploading that.
We can't copy and edit code from windows and it is MUCH easier to paste edited code to show where a correction may be needed that to attempt to edit a picture and post that.
Code is text. Please treat it as such.
I am sorry about it. So this is the practice question I did: SAS Macro Language 1: Essentials--> 4.1 Defining and Calling a Macro--> Level 1, 2 practice question
I did nothing change on original code, and when I submit it, it always failed to generate results. Here are the original code and log message.
%let type=Gold;
title "&type Customers";
proc sql number;
select Name, Age_Group, Type
from mc1.customers
where Type contains "&type";
quit;
title;
OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 %let type=Gold;
74 title "&type Customers";
75 proc sql number;
76 select Name, Age_Group, Type
77 from mc1.customers
78 where Type contains "&type";
ERROR: Invalid characters were present in the data.
ERROR: An error occurred while processing text data.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
79 quit;
NOTE: The SAS System stopped processing this step because of errors.
NOTE: PROCEDURE SQL used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds
80 title;
81
82 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
94
I found the same problem for level 2 question, When I copy the answer code to my SAS Studio, it shows following message:
Solution:
%macro orderstats(var=Total_Retail_Price, class=Customer_ID,
stats=mean, decimals=2);
options nolabel;
title 'Order Stats';
proc means data=mc1.orders maxdec=&decimals &stats;
var &var;
class &class;
run;
title;
options label;
%mend orderstats;
1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
72
73 %macro orderstats(var=Total_Retail_Price, class=Customer_ID,
74 stats=mean, decimals=2);
75 options nolabel;
76 title 'Order Stats';
77 proc means data=mc1.orders maxdec=&decimals &stats;
78 var &var;
79 class &class;
80 run;
81 title;
82 options label;
83 %mend orderstats;
84
85
86 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
Thanks so much! I am so stressed about this problem. I cannot continue my learning process due to this problem. Thanks again.
Not sure but it looks like perhaps some gibberish characters were introduced by the copy/paste action.
I find it helps sometimes to first copy the text into a simple text editor (not a word processor) like NOTEPAD on Windows. And then re-copy it and paste it. Or sometimes the gibberish will be more visible in the simple text editor and you can remove them.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.