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

So I will briefly explain my code structure before I dive into the issue.

 

1. I've a macro 

     %Sales (Outdata= , dt =, Outdata2= , Outdata3= );

      (

        I create a table &outdata by (Select * from XYZ);

        Proc SQL;

        Create table &Outdata._1 as 

          (  

           )

 

%mend Sales

 

2. Now I call the macro 

     %Sales (Outdata = sales_final_Oct17, dt='2017-10-01');

 

Libname ABCDEFG

 

3. I Create a data set

     Data ABCDEFG.all_sales_test;

      Set  ABCDEFG. all_Sales

      sales_final_Oct17_1;

       incur_month = month(rept_dt);

run;

 

Above (1 to 3) is the original code flow and it works fine.

 

My Problem:

 

I'm using a dynamic way of generating file name for each month (so that each month I do not manually enter file_name_month and date.

4. File name code

%let Last_Month = intnx('month', current_date,-1, "beginning");

Name = 'Sales_final';

Last_Month_Name = name|| put(&last_month, monyy7.);

Call SYMPUTX('Last_Month_Name_v', Last_Month_Name);

run;

 

Call Macro

%Sales(outdata=&Last_Month_Name, dt = 'Dynamic date');

 

Till this point everything works fine. The moment I create a data set similar to step 3 (above), the code breaks.

 

Libname ABCDEFG

 

     Data ABCDEFG.all_sales_test;

     Set  ABCDEFG. all_Sales

     Last_Month_Name_1;

     incur_month = month(rept_dt);

run;

Error Message: File ABCDEFG.LAST_MONTH_NAME_1.DATA does not exist.

 

What should I do to get rid of this error? It seems, if I pass a static name in the macro and then use the same name with "_1" it works fine but when I pass dynamic reference, then the data Set step fails with the above error message.

 

Any help is much appreciated. I'm new to SAS so excuse me if it's a silly question. Thanks. 

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

 

Data ABCDEFG.all_sales_test;
     Set  ABCDEFG. all_Sales
     Last_Month_Name_1;
     incur_month = month(rept_dt);
run;

 

I think you want

 

&last_month_name._1;

which will use the macro variable you created.

--
Paige Miller

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

 

Data ABCDEFG.all_sales_test;
     Set  ABCDEFG. all_Sales
     Last_Month_Name_1;
     incur_month = month(rept_dt);
run;

 

I think you want

 

&last_month_name._1;

which will use the macro variable you created.

--
Paige Miller
Reeza
Super User

That is incredibly hard to follow. It looks like things got cut off at places? 

Make sure to paste code using the insert code button in the Rich Text editor place. 


Did you check that your macro variables are being created and resolved properly? Given what you've posted that's not clear.

 

It's the { i } icon or the notebook icon.

 

Have you looked into CALL EXECUTE as well? that may simplify your process. 

 

When debugging macros use the following options so you can see the full log. 

 

options mlogic mprint symbolgen;

 

 

SteelersPitts
Obsidian | Level 7

I apologize Reeza. I will do a better job in formatting my code next time. According to my organization privacy rules, I can not publish the code here. I tried PaigeMiller's recommendation and it worked. 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 984 views
  • 2 likes
  • 3 in conversation