BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
NKormanik
Barite | Level 11

PC SAS 9.4 m7.

148  /* Invocation of the macro */
 
149  %confidence_all_folds(libname=SAS_1, response_variable=i_016, predictor1=i_127, predictor2=i_128, k_folds=5);
     -
     180
 
ERROR 180-322: Statement is not valid or it is used out of proper order.
 
Any suggestions regarding remedies greatly appreciated.
 
1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

Use a valid name for your macro.  Names in SAS are limited to 32 bytes.  (There is no need to write a novel in a name.)

 

Also avoid hiding continuation characters at the END of the lines of code.  Place them at the BEGINNING of the lines where they are much, much easier for HUMANS to scan.

1    %macro sweet_spot_and_confidence_all_folds
ERROR: Invalid macro name SWEET_SPOT_AND_CONFIDENCE_ALL_FOLDS.  It should be a valid SAS identifier no longer than 32 characters.
ERROR: A dummy macro will be compiled.
2    (libname=SAS_1
3    ,response_variable=i_016
4    ,predictor1=i_127
5    ,predictor2=i_128
6    ,k_folds=5
7    ,report_file=final_report_%sysfunc(today(), yymmdd10.).txt
8    );
9    %put _local_;
10   %mend;
11   %sweet_spot_and_confidence_all_folds ;
     -
     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

View solution in original post

5 REPLIES 5
SASKiwi
PROC Star

It appears your macro is generating SAS code containing syntax errors, hence the "Statement is not valid" error. 

Try adding the MPRINT option to provide more evidence, then post your complete SAS log showing the generated code along with any errors:

options mprint;

%confidence_all_folds(libname=SAS_1, response_variable=i_016, predictor1=i_127, predictor2=i_128, k_folds=5);

 

ballardw
Super User

Did you compile the macro in your current SAS session?

That would mean executing the code that starts %macro confidence_all_folds and ends with %mend.

Did is compile without errors? If the compilation step has errors or was not executed in the current session then the macro is not defined in the session in will return that error message.

 

If you didn't run the code then you need to find the code that defines the macro and execute it.

 

See this log for an attempt to execute a macro that I know has not been compiled in my current SAS session:

 

928  %dummymac (lib=jimmy);
     -
     180
WARNING: Apparent invocation of macro DUMMYMAC not resolved.

ERROR 180-322: Statement is not valid or it is used out of proper order.

It also appears that you perhaps edited the LOG from your attempt.

NKormanik
Barite | Level 11

This appears to the start of the macro.  Seems this might be where the error is.  If so, it needs to be edited in some way.  The error (??) is probably preventing the macro from being 'compiled' in the current session:

%macro sweet_spot_and_confidence_all_folds(
libname=SAS_1,
response_variable=i_016,
predictor1=i_127,
predictor2=i_128,
k_folds=5,
report_file=final_report_%sysfunc(today(), yymmdd10.).txt
);

 

 

Tom
Super User Tom
Super User

Use a valid name for your macro.  Names in SAS are limited to 32 bytes.  (There is no need to write a novel in a name.)

 

Also avoid hiding continuation characters at the END of the lines of code.  Place them at the BEGINNING of the lines where they are much, much easier for HUMANS to scan.

1    %macro sweet_spot_and_confidence_all_folds
ERROR: Invalid macro name SWEET_SPOT_AND_CONFIDENCE_ALL_FOLDS.  It should be a valid SAS identifier no longer than 32 characters.
ERROR: A dummy macro will be compiled.
2    (libname=SAS_1
3    ,response_variable=i_016
4    ,predictor1=i_127
5    ,predictor2=i_128
6    ,k_folds=5
7    ,report_file=final_report_%sysfunc(today(), yymmdd10.).txt
8    );
9    %put _local_;
10   %mend;
11   %sweet_spot_and_confidence_all_folds ;
     -
     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

 

ballardw
Super User

Then show the LOG where the compilation takes place, or the result that it compiled without errors.

 

If we need to debug the actual contents of the macro then you will have to share the code for the entire macro.

Experience for a few years of using macro code (only since 1992) tells me if I assume that the cause of the reported macro error is the statement the SAS compiler reports as a problem then I will be wrong roughly half the time. Quite often macro compilation errors are caused by logic errors prior to the proximate line(s) that SAS reports with an error. Usually because the prior logic error created a value or condition that fails to compile.

 

P.S. If your Report_file is an actual external to SAS file name I would suggest using the YYMMDDN8. format instead of YYMMDD10. The N means no separator so you get names that look like  "final_report20240820.txt" instead of "final_report2024/08/20.txt" which might get interpreted as a different file path than you expect.

 


@NKormanik wrote:

This appears to the start of the macro.  Seems this might be where the error is.  If so, it needs to be edited in some way.  The error (??) is probably preventing the macro from being 'compiled' in the current session:

%macro sweet_spot_and_confidence_all_folds(
libname=SAS_1,
response_variable=i_016,
predictor1=i_127,
predictor2=i_128,
k_folds=5,
report_file=final_report_%sysfunc(today(), yymmdd10.).txt
);

 

 


 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 447 views
  • 1 like
  • 4 in conversation