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

Hello, can anyone see in the code below why I might be getting the "ERROR 180-322: Statement is not valid or it is used out of proper order"?

 

libname x"\\...;

 

%macro copy_two(qtrname, year, filename);

 

libname A"\\...;
libname B"\\...;

 

data B.&filename.&qtrname.&year. (keep=ID cost);/*any other variables to keep go here*/
/*qtr=&qtrname.;
year=&year.;*/
set A.&filename.;
run;

 

proc sql;
   create table B..x&filename.&qtrname.&year. as select *
   from B.&filename.&qtrname.&year.;
quit;


%mend copy_two;

%macro loop(start,end);

%do i = &start. %to &end.;
%copy_two(Mar, &i., file);
%copy_two(Jun, &i., file);
%copy_two(Sep, &i., file);
%copy_two(Dec, &i., file);
%end;


%mend loop;

/*specify the years of interest*/
%loop(11,21)

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@2222 

Below code works.

Not sure where in your code you're using libref X or where you define and populate &filename. You certainly haven't shared all the code with us.

Also note that because you pass in string "file" to macro %loop() the only value &filename may have for things to work is file. Not sure if this is what you intended to do.  

 

Patrick_1-1664944994410.png

 

options dlcreatedir spool mprint symbolgen;
%let filename=FILE;
libname x "c:\temp\a";

data x.&filename;
  do id=1 to 5;
    cost=id*10;
    output;
  end;
run;

%macro copy_two(qtrname, year, filename);
  libname A "c:\temp\a";
  libname B "c:\temp\b";

  data B.&filename.&qtrname.&year. (keep=ID cost);/*any other variables to keep go here*/
    /*qtr=&qtrname.;
    year=&year.;*/
    set A.&filename.;
  run;

  proc sql;
    create table B.x&filename.&qtrname.&year. as select *
      from B.&filename.&qtrname.&year.;
  quit;

%mend copy_two;

%macro loop(start,end);
  %do i = &start. %to &end.;
    %copy_two(Mar, &i., file);
    %copy_two(Jun, &i., file);
    %copy_two(Sep, &i., file);
    %copy_two(Dec, &i., file);
  %end;
%mend loop;

/*specify the years of interest*/
%loop(11,21)

 

View solution in original post

13 REPLIES 13
Kurt_Bremser
Super User

The first possible issue is right in the first statement:

libname x"\\...;

The physical path misses the closing double quote.

But for real diagnostics, we MUST see the whole log of your code, from the beginning to at least up to the first ERROR message.

Use this button to post the log:

Bildschirmfoto 2020-04-07 um 08.32.59.jpg

2222
Calcite | Level 5

Hi Kurt,

Thank you for looking at this; the code includes the "  at the end. this is the log error:

 

180: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.
NOTE: PROC SQL set option NOEXEC and will continue to check the syntax of statements.
NOTE: The SAS System stopped processing this step because of errors.

 

Unfortunately, I'm not allowed to show the code exactly or the log, but I hope this helps a bit.

2222
Calcite | Level 5
sorry Kurt, I'm not allowed to
Patrick
Opal | Level 21

...and as the log tells you add at the beginning of your code: options spool;

Patrick_0-1664875783126.png

 

Why are there two full stops?

Patrick_0-1664875995529.png

 

 

 

2222
Calcite | Level 5
it's not the dots that's causing the error, and we shouldn't need options spool
Tom
Super User Tom
Super User

Make sure to turn on the MPRINT option so you can see the SAS code that the macro generates (and that the error message is talking about).

 

And you definitely cannot have a member name that starts with a period.

create table B..x&filename.&qtrname.&year. 

Unless you set option VALIDMEMNAME=EXTEND.  And even then you would need to have the macro generate a name literal.

create table B.".x&filename.&qtrname.&year."n 
2222
Calcite | Level 5
thank you Tom, but i have tried:
proc sql;
    create table B.test&filename.&qtrname.&year. as select *
   from B.&filename.&qtrname.&year.;
quit;
same error given, so i don't think the period made any difference
Tom
Super User Tom
Super User

@2222 wrote:
thank you Tom, but i have tried:
proc sql;
    create table B.test&filename.&qtrname.&year. as select *
   from B.&filename.&qtrname.&year.;
quit;
same error given, so i don't think the period made any difference

So you fixed one error, but you still have another error.

Your code does not look that complicated so it is highly likely the error is actually being generated by something you ran BEFORE the code you posted.

2222
Calcite | Level 5
but the code i posted (to begin thread) is the whole program
Patrick
Opal | Level 21

@2222 

Then eventually you really should set at the very beginning of your program

options mprint symbolgen spool;

As for spool: That's what the SAS log recommends you to do.

Patrick_0-1664943365804.png

Also make sure that you run your code out of a fresh new SAS session (with EG for example disconnect from your session before re-running).

Patrick
Opal | Level 21

@2222 

Below code works.

Not sure where in your code you're using libref X or where you define and populate &filename. You certainly haven't shared all the code with us.

Also note that because you pass in string "file" to macro %loop() the only value &filename may have for things to work is file. Not sure if this is what you intended to do.  

 

Patrick_1-1664944994410.png

 

options dlcreatedir spool mprint symbolgen;
%let filename=FILE;
libname x "c:\temp\a";

data x.&filename;
  do id=1 to 5;
    cost=id*10;
    output;
  end;
run;

%macro copy_two(qtrname, year, filename);
  libname A "c:\temp\a";
  libname B "c:\temp\b";

  data B.&filename.&qtrname.&year. (keep=ID cost);/*any other variables to keep go here*/
    /*qtr=&qtrname.;
    year=&year.;*/
    set A.&filename.;
  run;

  proc sql;
    create table B.x&filename.&qtrname.&year. as select *
      from B.&filename.&qtrname.&year.;
  quit;

%mend copy_two;

%macro loop(start,end);
  %do i = &start. %to &end.;
    %copy_two(Mar, &i., file);
    %copy_two(Jun, &i., file);
    %copy_two(Sep, &i., file);
    %copy_two(Dec, &i., file);
  %end;
%mend loop;

/*specify the years of interest*/
%loop(11,21)

 

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 13 replies
  • 1801 views
  • 1 like
  • 4 in conversation