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

Below is the code I was using

%macro ins(ruleset_id);

proc sql noprint;

insert into RAS.RATE_ASSIGNMENT_BIZ

(BRM_RULESET_ID,

BRM_RULESET_NAME,

RATE_ASSIGNMENT_NAME,

XREF_ANALYSIS_ID,

ANALYST_ID,

EXISTING_GLOBAL_MIN ,

EXISTING_GLOBAL_MEDIAN,

EXISTING_GLOBAL_MAX,

EXISTING_LOCAL_MIN,

EXISTING_LOCAL_MEDIAN,

EXISTING_LOCAL_MAX,

SALES_LEVEL_1_DESCRIPTION,

ELEMENT,

PRICE_LIST_NAME,

ACTION_STATUS,

ACTION_REASON,

ANALYST_ID,

ANALYST_NAME)

SELECT BRM_RULESET_ID,BRM_RULESET_NAME,RATE_ASSIGNMENT_NAME,XREF_ANALYSIS_ID,ANALYST_ID,

EXISTING_GLOBAL_MIN ,

EXISTING_GLOBAL_MEDIAN,

EXISTING_GLOBAL_MAX,

EXISTING_LOCAL_MIN,

EXISTING_LOCAL_MEDIAN,

EXISTING_LOCAL_MAX,

SALES_LEVEL_1_DESCRIPTION,

ELEMENT,

PRICE_LIST_NAME,

ACTION_STATUS,

ACTION_REASON,

ANALYST_ID,

ANALYST_NAME

FROM progress.RAS_COMPLETED_RATES

WHERE BRM_RULESET_ID = &ruleset_id;

run;

%mend ins;

I am getting the erorr "ERROR 180-322: Statement is not valid or it is used out of proper order." When I call this macro inside a datasetp.

Can you please help me with the issue here.

1 ACCEPTED SOLUTION

Accepted Solutions
Quentin
Super User

Hi,

Can you please show the code where you call the macro?

If by "call this macro inside a datastep" you mean something like:

data want;

  set have;

  %ins(5)

 

  *more data step code here;

run;

You will have problems, because you would be trying to run a PROC SQL step inside a data step, which doesn't work.   The proc SQL step will end the data step, and any data step code after the macro invocation will cause an error like you're getting.

If you are trying to generate a bunch of macro calls from data, look into call execute.  It allows you to generate the PROC SQL code, but the code is not actually executed until after the data step is completed.

HTH,

--Q.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.

View solution in original post

5 REPLIES 5
ChrisHemedinger
Community Manager

You cannot call a PROC SQL step within a DATA step, and since this macro expands to a full PROC SQL step, the resulting syntax is invalid.

If you really need this step to execute for every iteration (observation) in a DATA step, you can use DOSUBL to invoke it.

Here's a paper on the topic:

http://support.sas.com/resources/papers/proceedings12/227-2012.pdf

And some examples from my blog:

Tracking progress in your program with SAS Enterprise Guide: another trick

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.
Quentin
Super User

Hi,

Can you please show the code where you call the macro?

If by "call this macro inside a datastep" you mean something like:

data want;

  set have;

  %ins(5)

 

  *more data step code here;

run;

You will have problems, because you would be trying to run a PROC SQL step inside a data step, which doesn't work.   The proc SQL step will end the data step, and any data step code after the macro invocation will cause an error like you're getting.

If you are trying to generate a bunch of macro calls from data, look into call execute.  It allows you to generate the PROC SQL code, but the code is not actually executed until after the data step is completed.

HTH,

--Q.

BASUG is hosting free webinars Next up: Mike Sale presenting Data Warehousing with SAS April 10 at noon ET. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
ykk
Obsidian | Level 7 ykk
Obsidian | Level 7

Thanks Quentin Call Execute Worked for me.

ballardw
Super User

How are you call this in a data set?

If you paste the above code with a value for &ruleset_id into the data step currently calling this macro will it run?

ChrisHemedinger
Community Manager

And one more idea, as I examine the SQL code a bit more.  It looks like you're trying to "enrich" another data set with some SAS Business Rules Manager output.  Do you think that you might instead be able to refactor your INSERT/SELECT code into a JOIN where you combine the two data sources based on matching criteria?  If you're using SAS Enterprise Guide, you might be able to play with the Query Builder to join the two data sets into your desired output -- or at least an output that you could then append back on to the RAS.RATE_ASSIGNMENT_BIZ target table.

Chris

It's time to register for SAS Innovate! Join your SAS user peers in Las Vegas on April 16-19 2024.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 2850 views
  • 3 likes
  • 4 in conversation