I have this macro
%macro run_cas_ma;
libname _tmpcas_ cas caslib="CASUSER";
proc cas;
/* Ensure that the session is set correctly */
session %sysfunc(getlsessref(&dataset_lib));
/* Load the necessary action set */
loadactionset %sysfunc(quote(timeData));
action runTimeCode /
table={
caslib=%sysfunc(quote(%sysfunc(getlcaslib(&dataset_lib))))%str(,)
name=%sysfunc(quote(&dataset_name))
} /* Table definition comes first */
objOut={
{
table={
caslib=%sysfunc(quote(%sysfunc(getlcaslib(_tmpcas_))))%str(,)
name=%qsysfunc(quote(outStatTemp)) %str(,)
replace=%sysfunc(quote(true))
}%str(,)
objRef=%str('outStat')
}
}
/* Conditionally add forecast output if plotForecastViya is set to 1 */
%if &plotForecastViya = 1 %then %do;
%str(,)
{
table={
caslib=%sysfunc(quote(%sysfunc(getlcaslib(_tmpcas_))))%str(,)
name=%sysfunc(quote(outFcastTemp)) %str(,)
replace=%sysfunc(quote(true))
}%str(,)
objRef=%str('outFcast')
}
%end;
seasonality=12
timeId={name=%str('date') %str(,) FORMAT=%sysfunc(quote(_DATA_))}
interval="Month"
nlFormat=true
series={'sale'}
require={{pkg='TSM'}}
code=%str(%')
declare object myModel(TSM);
declare object mySpec(ARIMASpec);
rc = mySpec.Open();
/* Loop to assign values to ma[&i.] */
%do i=1 %to &map.;
ma[&i.] = &i.;
%end;
rc = mySpec.AddMAPoly(ma);
rc = mySpec.SetOption("noint",1);
rc = mySpec.SetOption("method","CLS");
rc = mySpec.close();
/* Initialize the model */
rc = myModel.Initialize(mySpec);
rc = myModel.SetY(&dependVariable);
rc = myModel.SetOption('lead', &forecastPeriods);
rc = myModel.SetOption("alpha",0.05);
rc = myModel.Run();
/* Collect forecast if plotForecastViya is set to 1 */
%if &plotForecastViya = 1 %then %do;
declare object outFcast(TSMFor);
rc = outFcast.Collect(myModel);
%end;
declare object outStat(TSMSTAT);
rc = outStat.Collect(myModel);
%str(%');
run;
%mend run_cas_ma;
%run_cas_ma
This i giving me error
MPRINT(__CODE): action runTimeCode / table={ caslib="CASUSER(swkuma)", name="PRICEDATA" } objOut={ { table={ caslib="CASUSER",
name="outStatTemp" , replace="true" }, objRef='outStat' } } , { table={ caslib="CASUSER", name="outFcastTemp" , replace="true" },
objRef='outFcast' } seasonality=12 timeId={name='date' , FORMAT="_DATA_"} interval="Month" nlFormat=true series={'sale'}
require={{pkg='TSM'}} code=' declare object myModel(TSM); declare object mySpec(ARIMASpec); rc =
mySpec.Open(); ma[1] = 1; rc = mySpec.AddMAPoly(ma); rc = mySpec.SetOption("noint",1);
rc = mySpec.SetOption("method","CLS"); rc = mySpec.close(); rc =
myModel.Initialize(mySpec); rc = myModel.SetY(sale); rc = myModel.SetOption('lead', 12); rc =
myModel.SetOption("alpha",0.05); rc = myModel.Run(); declare object outFcast(TSMFor); rc =
outFcast.Collect(myModel); declare object outStat(TSMSTAT); rc = outStat.Collect(myModel);
';
ERROR: A name token was expected
ERROR: action runTimeCode / table = { caslib = 'CASUSER(swkuma)' , n
ERROR: ame = 'PRICEDATA' } objOut = { { table = { caslib = 'CASUSER'
ERROR: , name = 'outStatTemp' , replace = 'true' } , objRef = 'outS
ERROR: tat' } } , { table = { caslib = 'CASUSER' , name = 'outFcastT
ERROR: emp' , replace = 'true' } , objRef = 'outFcast' } seasonality
ERROR: = 12 timeId = { name = 'date' , FORMAT = '_DATA_' } interval
ERROR: = 'Month' nlFormat = TRUE series = { 'sale' } require = { {
ERROR: pkg = 'TSM' } } code = ' declare object myModel(TS
ERROR: M); declare object mySpec(ARIMASpec); r
ERROR: c = mySpec.Open(); ma[1] = 1; rc =
ERROR: mySpec.AddMAPoly(ma); rc = mySpec.SetOption("noint
ERROR: ",1); rc = mySpec.SetOption("method","CLS");
ERROR: rc = mySpec.close();
ERROR: rc = myModel.Initialize(mySpec); rc = myModel.Set
ERROR: Y(sale); rc = myModel.SetOption(' lead ', 12);
ERROR: rc = myModel.SetOption("alpha",0.05); rc =
ERROR: myModel.Run(); declare object outFcast(TSMFor)
ERROR: ; rc = outFcast.Collect(myModel);
ERROR: declare object outStat(TSMSTAT); rc = ou
ERROR: tStat.Collect(myModel); ' ;
ERROR: ^
NOTE: The submitted statements have been canceled.
Please help me to debug why this is coming and how to resolve this . Thanks!!
Use this little icon :
to paste your code like it should be:
%macro run_cas_ma;
libname _tmpcas_ cas caslib="CASUSER";
proc cas;
/* Ensure that the session is set correctly */
session %sysfunc(getlsessref(&dataset_lib));
/* Load the necessary action set */
loadactionset %sysfunc(quote(timeData));
action runTimeCode /
table={
caslib=%sysfunc(quote(%sysfunc(getlcaslib(&dataset_lib))))%str(,)
name=%sysfunc(quote(&dataset_name))
} /* Table definition comes first */
objOut={
{
table={
caslib=%sysfunc(quote(%sysfunc(getlcaslib(_tmpcas_))))%str(,)
name=%qsysfunc(quote(outStatTemp)) %str(,)
replace=%sysfunc(quote(true))
}%str(,)
objRef=%str('outStat')
}
}
/* Conditionally add forecast output if plotForecastViya is set to 1 */
%if &plotForecastViya = 1 %then %do;
%str(,)
{
table={
caslib=%sysfunc(quote(%sysfunc(getlcaslib(_tmpcas_))))%str(,)
name=%sysfunc(quote(outFcastTemp)) %str(,)
replace=%sysfunc(quote(true))
}%str(,)
objRef=%str('outFcast')
}
%end;
seasonality=12
timeId={name=%str('date') %str(,) FORMAT=%sysfunc(quote(_DATA_))}
interval="Month"
nlFormat=true
series={'sale'}
require={{pkg='TSM'}}
code=%str(%')
declare object myModel(TSM);
declare object mySpec(ARIMASpec);
rc = mySpec.Open();
/* Loop to assign values to ma[&i.] */
%do i=1 %to &map.;
ma[&i.] = &i.;
%end;
rc = mySpec.AddMAPoly(ma);
rc = mySpec.SetOption("noint",1);
rc = mySpec.SetOption("method","CLS");
rc = mySpec.close();
/* Initialize the model */
rc = myModel.Initialize(mySpec);
rc = myModel.SetY(&dependVariable);
rc = myModel.SetOption('lead', &forecastPeriods);
rc = myModel.SetOption("alpha",0.05);
rc = myModel.Run();
/* Collect forecast if plotForecastViya is set to 1 */
%if &plotForecastViya = 1 %then %do;
declare object outFcast(TSMFor);
rc = outFcast.Collect(myModel);
%end;
declare object outStat(TSMSTAT);
rc = outStat.Collect(myModel);
%str(%');
run;
%mend run_cas_ma;
%run_cas_ma
First of all: writing a macro without parameters is bad programming practice.
Second thing what are:
timeData, outFcastTemp are those mcarovariables ? or constant texts ?
Where the &map. macrovariabel comes from?
where is the definition of array "ma", that one used here:
%do i=1 %to &map.;
ma[&i.] = &i.;
%end;
?
Mprint in the text you pasted comes from macro: __CODE, where is that macro defined?
Assigning TRUE/FALSE values to option:
replace=%sysfunc(quote(true))
I think should be like this:
replace=1
or
replace=True
(see example: https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/caspg/p1668p6hhivls3n11q05kk6h1zgj.htm)
Single-quotes embedded improperly in "code":
Etc., etc., etc.
"NOTE: The quoted string currently being processed has become more than 262 bytes long. You might have unbalanced quotation marks."
If you can't find the problem in the code, try to strip down the macro until it works, and than add code part by part until you find the problem.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.