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

Hello,

 

I am struggling to incorporate three different macro variables into a program that otherwise works just fine. I've tried searching for solutions online, but am struggling to find anything that fixes these problems.

 

The macro variables are set up at the beginning of the program:

%let month_number = 8;

%let month = 202308;

%let day = 20230831;

 

Firstly, I am trying to create a table:

data table2;

    set table1;

    if PROCESS_YYYYMM <= (INCURRED_DT_YR_2) * 100 + &month_number.

    then...

...

I'm getting a syntax error when I try using the &month_number. variable.

 

Secondly, the program has a step where it connects to a server and creates a table with the following WHERE statement:

WHERE

t1.PROCESS_YYYYMM between '201601' and '202308' and

t2.INCURRED_DT_DAY between '20160101' and '20230831'

The program works just fine like this, but I'd like to incorporate the &month. and &day. variables in lieu of the end dates shown here. How do I need to format this? I've tried a number of different possibilities with apostrophes, quotation marks, and even tried using a %syslput line for each variable before this table gets created, but nothing that I've tried seems to work. I keep getting ERROR: CLI execute error and the table doesn't get created.

 

Any help greatly appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

If the macro is generating SAS code then just use double quotes.

     t1.PROCESS_YYYYMM between '201601' and "&month"
 and t2.INCURRED_DT_DAY between '20160101' and "&day"

If you are pushing that code into some external database that does not recognize double quotes are character constants then you will have to work a little harder to get the single quotes instead.  Try:

     t1.PROCESS_YYYYMM between '201601' and %bquote('&month')
 and t2.INCURRED_DT_DAY between '20160101' and %bquote('&day')

 

View solution in original post

3 REPLIES 3
Tom
Super User Tom
Super User

If the macro is generating SAS code then just use double quotes.

     t1.PROCESS_YYYYMM between '201601' and "&month"
 and t2.INCURRED_DT_DAY between '20160101' and "&day"

If you are pushing that code into some external database that does not recognize double quotes are character constants then you will have to work a little harder to get the single quotes instead.  Try:

     t1.PROCESS_YYYYMM between '201601' and %bquote('&month')
 and t2.INCURRED_DT_DAY between '20160101' and %bquote('&day')

 

Wickedestjr
Fluorite | Level 6

Thank you Tom! That worked.

 

Do you know what I should try for the month_number variable?

Tom
Super User Tom
Super User

If the code comparing the variable to a quoted string worked then you don't want to treat it as if it was a number like you have in the other code.  Unless you are talking about two different variables (from different datasets) that just happen to have the same name.

 

So what do you think this code is doing?

    if PROCESS_YYYYMM <= (INCURRED_DT_YR_2) * 100 + &month_number.

What is INCURRED_DT_YR_2?  Is that a numeric variable?  What types of values does it have?

 

It it is a NUMBER than convert it to a character string and append a character version of &MONTH_NUMBER.

    if PROCESS_YYYYMM <=  put(INCURRED_DT_YR_2,Z4.) || put( &month_number.,Z2.)

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!

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
  • 3 replies
  • 870 views
  • 2 likes
  • 2 in conversation