DATA Step, Macro, Functions and more

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

Accepted Solution Solved
Reply
Contributor
Posts: 36
Accepted Solution

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

[ Edited ]

I have searched some info about this error,but it seems none match mine,may someone familiar with this error take a look.

"Code generated by a SAS macro, or submitted with a "submit selected" operation in your editor, can leave off a semicolon inadvertently." it is still abstruse for me to explore in my code by this comment.may someone give any advice..thanks!


%let cnt=500;
%let dataset=fund_sellList;
%let sclj='~/task_out_szfh/fundSale/';
%let wjm='sz_fundSale_';

%macro write_dx;
    options spool;
    data _null_;
    cur_date=put(today(),yymmdd10.);
    cur_date=compress(cur_date,'-');
    cnt=&cnt;
    retain i;
    set &dataset;
    if _n_=1 then i=cnt;
        if _n_<=i then do;
            abs_filename=&sclj.||&wjm.||cur_date||'.dat';
            abs_filename=compress(abs_filename,'');
            file anyname filevar=abs_filename encoding='utf8' nobom ls=32767 DLM='|';
                put cst_id @;
                put '@|' @;
                put cust_name @;
                put '@|' ;
        end;
    run;
%mend write_dx;

%write_dx();

 

and if I am not using macro,there is no error.

data _null_;

    options spool;
    cur_date=put(today(),yymmdd10.);
    cur_date=compress(cur_date,'-');
    cnt=&cnt;
    retain i;
    set &dataset;
    if _n_=1 then i=cnt;
        if _n_<=i then do;
            abs_filename=&sclj.||&wjm.||cur_date||'.dat';
            abs_filename=compress(abs_filename,'');
            file anyname filevar=abs_filename encoding='utf8' nobom ls=32767 DLM='|';
                put cst_id @;
                put '@|' @;
                put cust_name @;
                put '@|' ;
        end;
    run;


Accepted Solutions
Solution
‎03-14-2018 07:51 PM
Respected Advisor
Posts: 4,668

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

@Geo-

The error message itself is pretty clear and you'll get it if you either use a SAS statement that doesn't exist or if there has been an error right before your statement which "confused" the compiler so it can't recognize the valid statement anymore.

 

When using SAS Macro language then basically the SAS Macro generates SAS code and then the SAS code gets compiled and executed. So if the macro generates wrong SAS code then you can get such an error message.

 

Having said all of the above: I couldn't really see something wrong in your code so I had to create some sample data and run it.

 

...the reason why things are not working for you:

You define the macro without parameters and without a bracket BUT you call it with a bracket. To avoid the error either use brackets or don't (I prefer using brackets always).

So to fix your code the only thing you need to do is to change your macro definition as below:

%macro write_dx();

View solution in original post


All Replies
Super User
Posts: 9,878

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

Get your SAS code to run properly before wrapping it in a macro.

Since your macro has no macro-specific code, and uses no macro parameters, it is not needed anyway.

Removing the macro definition will enable the syntax coloration of your Studio or Enterprise Guide, and looking at the log will show you that SAS complains about

comress

in line

cur_date=comress(cur_date,'-');

which is not a SAS function. I guess you wanted to use compress().

And you don't need compress at all if you use the proper format:

cur_date = put(today(),yymmddn8.);
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 36

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

Posted in reply to KurtBremser
sorry it's cacography,my code on the server is using "compress"
Super User
Posts: 9,878

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

Then copy/paste the log as described in https://communities.sas.com/t5/help/faqpage/faq-category-id/posting?nobounce

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 36

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

Posted in reply to KurtBremser
sorry,for the whole log is on my server and can not connect to Internet.So I could only type letter by letter..the only message is this error..
Super User
Posts: 9,878

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

Open the log window.

Mark the relevant section.

Hit Ctrl-C.

Switch to the browser, hit Ctrl-V.

Any text displayed in Windows can be copy/pasted that way.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Contributor
Posts: 36

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

Posted in reply to KurtBremser
thank you for your patience..I mean we use intranet..
Super User
Posts: 9,878

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


@Geo- wrote:
thank you for your patience..I mean we use intranet..

And?

 

Text on your screen can be copy/pasted. I guess your intranet is not sending you stone plates with text chiseled in.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Solution
‎03-14-2018 07:51 PM
Respected Advisor
Posts: 4,668

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

@Geo-

The error message itself is pretty clear and you'll get it if you either use a SAS statement that doesn't exist or if there has been an error right before your statement which "confused" the compiler so it can't recognize the valid statement anymore.

 

When using SAS Macro language then basically the SAS Macro generates SAS code and then the SAS code gets compiled and executed. So if the macro generates wrong SAS code then you can get such an error message.

 

Having said all of the above: I couldn't really see something wrong in your code so I had to create some sample data and run it.

 

...the reason why things are not working for you:

You define the macro without parameters and without a bracket BUT you call it with a bracket. To avoid the error either use brackets or don't (I prefer using brackets always).

So to fix your code the only thing you need to do is to change your macro definition as below:

%macro write_dx();
Super Contributor
Posts: 331

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

Hello,

Try removing the parentheses in the macro call :
%write_dx;
Regular Contributor
Posts: 153

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

Hi,

 

when not using macro parameters, add brackets to the macro name definition

 

%macro write_dx();

 or remove the brackets in the macro call

%write_dx;

to fix the error. I prefer for my part option 1.

 

________________________

- Cheers -

Contributor
Posts: 36

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

thank you!both of your answers pointed out
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 11 replies
  • 108 views
  • 0 likes
  • 5 in conversation