Hi,
I am trying to run below macro and it's showing the error.
[SAS 9.4]
MACRO:
%Macro GetCheck(VariableList, ChoiceList, c);
%Let InSplitVar = %Scan (%bquote(&&&VariableList.), &c., %str(|));
%Let Decision = %Scan(%bquote(&&&ChoiceList.), &c., %str(|));
and &InSplitVar. &Decision.
%Mend GetCheck;
ERROR:
NOTE: Line generated by the macro variable "DECISION".
1 CORPORATE,GMAIL.COM,HOTMAIL.COM,LIVE.COM,REDIFF.COM,YAHOO.COM
---------
22
76
NOTE: Line generated by the macro variable "DECISION".
1 MSN.COM,MISSPELLED,SIFY.COM,UNKNOWN
-------
22
76
ERROR 22-322: Syntax error, expecting one of the following: (, [, {.
ERROR 76-322: Syntax error, statement will be ignored.
NOTE: Line generated by the macro variable "INSPLITVAR".
1 1
-
22
ERROR 22-322: Syntax error, expecting one of the following: !, !!, &, (, *, **, +, -, /, <, <=,
<>, =, >, ><, >=, AND, EQ, GE, GT, LE, LT, MAX, MIN, NE, NG, NL, OR, [, ^=, {, |,
||, ~=.
Thanks in advance.
Show the whole step in which you call the macro; if it reads one or more datasets, provide example data (data steps with datalines).
Attached the sample dataset and 3 macros I am trying to run:
%Macro ApplyTrees(TotalTrees);
%Do TreeCount = 1 %To &TotalTrees.;
%CreateChoices(&TreeCount.);
proc sql noprint;
select Prediction into :PredictedValue separated by "|"
from Tree_&TreeCount.;
quit;
Data _NULL_;
Set Tree_&TreeCount.; Call Symput("NodeCount", Compress(_N_));
Run;
%ApplyChoices(&TreeCount.);
%End;
%Mend ApplyTrees;
%Macro CreateChoices(TreeCount);
%Do x = 1 %To 5;
%Global ChoiceList&x.;
%Global VariableList&x.;
proc sql noprint;
select Decision&x. into :ChoiceList&x. separated by "|"
from Tree_&TreeCount.;
quit;
proc sql noprint;
select InSplitVar&x.
into :VariableList&x. separated by "|"
from Tree_&TreeCount.; quit;
%End;
%Mend CreateChoices;
%Macro GetCheck(VariableList, ChoiceList, c);
%Let InSplitVar = %Scan (%bquote(&&&VariableList.), &c., %str(|));
%Let Decision = %Scan(%bquote(&&&ChoiceList.), &c., %str(|));
and &InSplitVar. &Decision.
%Mend GetCheck;
%Macro GetCheck(VariableList, ChoiceList, c);
%Let InSplitVar = %Scan (%bquote(&&&VariableList.), &c., %str(|));
%Let Decision = %Scan(%bquote(&&&ChoiceList.), &c., %str(|));
and &InSplitVar. = %str(&Decision.)
%Mend GetCheck;
%Macro ApplyChoices(TreeCount);
Data OutSample;
Set OutSample;
%Do b = 1 %To &NodeCount.;
If 1 = 1
%Do a = 1 %To 5;
%GetCheck(VariableList&a., ChoiceList&a., &b.)
%End;
%Let Prediction = %Scan(&PredictedValue., &b., %str(|));
Then PredictedValue_&TreeCount. = "&Prediction.";
%End;
Run;
%Mend ApplyChoices;
%ApplyTrees(1);
You attached a CSV file, but I don't see any SAS code to read that CSV file into a dataset.
Given that the error message is complaining about text with a lot of commas in it I suspect that you problem was with reading the CSV file. You appear to have read the commas from the CSV into the values of the SAS variables.
The file I attached is the output from another function (i.e., not required to read the file in the above code). I attached sample data for reference.
Did you try running the steps in those macros as normal SAS statements first? Can you get the process to work without macros?
Also your macros have a lot of "magical" macro variables. That is they are referencing macro variables that are neither input parameters or defined as either %LOCAL or %GLOBAL by the macro. Did you check that you are not accidentally re-using the same macro variables and causing the confusion?
@Tom wrote:
You attached a CSV file, but I don't see any SAS code to read that CSV file into a dataset.
Given that the error message is complaining about text with a lot of commas in it I suspect that you problem was with reading the CSV file. You appear to have read the commas from the CSV into the values of the SAS variables.
Given this guess by @Tom, have you@Deepender actually looked at the data set you are using (not the sample one you sent us) to see if some stray commas have caused your .csv file to be improperly read, or are affecting your macros?
ACTUALLY LOOK AT YOUR DATA in the data set (not in the .csv file)! It's a very simple and effective tool for debugging.
@PaigeMiller wrote:
@Tom wrote:
You attached a CSV file, but I don't see any SAS code to read that CSV file into a dataset.
Given that the error message is complaining about text with a lot of commas in it I suspect that you problem was with reading the CSV file. You appear to have read the commas from the CSV into the values of the SAS variables.
Given this guess by @Tom, have you@Deepender actually looked at the data set you are using (not the sample one you sent us) to see if some stray commas have caused your .csv file to be improperly read, or are affecting your macros?
ACTUALLY LOOK AT YOUR DATA in the data set (not in the .csv file)! It's a very simple and effective tool for debugging.
AND look at your CSV file with a text editor (Notepad, WordPad, the SAS editor etc.) not a spreadsheet. The spreadsheets are notorious for disguising the appearance of certain types of data from CSV files.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.