BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NCSU_2016
Fluorite | Level 6

Hi All,

 

I am still somewhat new to using SAS/IML. In executing the code listed below, the &start value is only recognized for non-negative values. Here is the code:

 

 

*creates 3-month shut down rule macro;

%macro threemonth(dst,shutdown,stay_acc,exit_acc);
proc iml;
use &dst;
read all var {jun04 jul04 aug04 sep04 oct04 nov04 dec04 jan05 feb05 mar05 apr05 may05 jun05 jul05 aug05 sep05 oct05 nov05 dec05 jan06 feb06 mar06 apr06 may06 jun06 jul06 aug06 sep06 oct06 nov06 dec06 jan07 feb07 mar07 apr07 may07 jun07 jul07 aug07 sep07 oct07 nov07 dec07 jan08 feb08 mar08 apr08 may08 jun08 jul08 aug08 sep08 oct08 nov08 dec08 jan09 feb09 mar09 apr09 may09 jun09 jul09 aug09 sep09 oct09 nov09 dec09 jan10 feb10 mar10 apr10 may10 jun10 jul10 aug10 sep10 oct10 nov10 dec10 jan11 feb11 mar11 apr11 may11 jun11 jul11 aug11 sep11 oct11 nov11 dec11 jan12 feb12 mar12 apr12 may12 jun12 jul12 aug12 sep12 oct12 nov12 dec12 jan13 feb13 mar13 apr13 may13 jun13 jul13 aug13 sep13 oct13 nov13 dec13 jan14 feb14 mar14 apr14 may14 jun14 jul14 aug14 sep14 oct14 nov14 dec14 jan15 feb15 mar15 apr15 may15} into month_prof;
n_months=ncol(month_prof);
n_farms=nrow(month_prof);
profits = j(n_farms,n_months,0);
Theory_exit = j(n_farms,n_months,0);
Theory_stay = j(n_farms,n_months,0);
Real_exit = j(n_farms,n_months,.);
Real_stay = j(n_farms,n_months,.);
Accuracy_stay = j(n_farms,n_months,.);
Accuracy_exit = j(n_farms,n_months,.);
do i=1 to n_farms;
do j=4 to n_months;
profits[i,j]=month_prof[i,j-1]+month_prof[i,j-2]+month_prof[i,j-3];
if ((month_prof[i,j]=0)*(month_prof[i,j-1]^=0))=1 then real_exit[i,j]=1;

if profits[i,j]< &shutdown then theory_exit[i,j]=1;
if real_exit[i,j]=. then theory_exit[i,j]=.;

if month_prof[i,j]^=0 then real_stay[i,j]=1;

if profits[i,j] >= &shutdown then theory_stay[i,j]= 1;
if real_stay[i,j]=. then theory_stay[i,j]=.;


if real_exit[i,j]^=. then accuracy_exit[i,j]=(theory_exit[i,j]=real_exit[i,j]);

if real_stay[i,j]^=. then accuracy_stay[i,j]=(theory_stay[i,j]=real_stay[i,j]);
end;
end;
&acc_stay=accuracy_stay[:];
print &acc_stay &shutdown;
&acc_exit=accuracy_exit[:];
print &acc_exit &shutdown;
quit;
%mend;


*creates macro for 3 month SEARCH from 'start' to 'end' by 'step' of shut-down rule;
%macro threemonthsearch(dst,shutdown,acc_stay,acc_exit,start,end,step);
%do &shutdown=&start %to &end %by &step;
%threemonth(&dst,&shutdown,&acc_stay,&acc_exit);
%end;
%mend; 

 

*Executes macro for 3 month search of shut-down rule;

%threemonthsearch(work.prof,shutdown,prof_3mo_stay,prof_3mo_exit,-6000,6000,1000);

 

 

 

 

The code executes for for all non-zero steps but does not execute for -6000,-5000,-4000,-3000,-2000,-1000. Any thoughts or suggestions are greatly appreciated.

 

Another interesting point is that these values are executed when the &shutdown is removed from the print statements.

 

The error message for those values is:

 

 

 

NOTE: Line generated by the macro variable "SHUTDOWN".
56 -1000
_
22
200
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, a numeric constant, a datetime constant,
a missing value, ;, (, (|, ',', /, [, {.
 
ERROR 200-322: The symbol is not recognized and will be ignored.
 
 
 
 
Thanks!
1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hi @NCSU_2016,

 

I'm not really familiar with SAS/IML (and I don't have a license for it), but according to the online documentation plain numbers are not among the expected items in a PRINT statement. As the content of macro variable SHUTDOWN is just constant text (which happens to be a number), it should be a step forward to put the macro variable reference between double quotes in the two PRINT statements (cf. item "message" in the documentation): "&shutdown"

View solution in original post

2 REPLIES 2
ballardw
Super User

I don't know if this actually is from your code but when I attempted to compile your macro threemonthsearch the parameter start came across as st?art to the compiler generating a error about parameter delimiters.

 

You might try retyping the parameter list from scratch and see if that helps.

After that correction I was able to generate the loop values for shutdown okay.

 

You might also want to clear the log and rerun the code without the suggested fix and examine closely.

FreelanceReinh
Jade | Level 19

Hi @NCSU_2016,

 

I'm not really familiar with SAS/IML (and I don't have a license for it), but according to the online documentation plain numbers are not among the expected items in a PRINT statement. As the content of macro variable SHUTDOWN is just constant text (which happens to be a number), it should be a step forward to put the macro variable reference between double quotes in the two PRINT statements (cf. item "message" in the documentation): "&shutdown"

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

From The DO Loop
Want more? Visit our blog for more articles like these.
Discussion stats
  • 2 replies
  • 1279 views
  • 0 likes
  • 3 in conversation