DATA Step, Macro, Functions and more

Issue Creating a Table based on Macro's Parameter Name

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Issue Creating a Table based on Macro's Parameter Name

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. 

 


Accepted Solutions
Solution
2 weeks ago
Trusted Advisor
Posts: 1,934

Re: Issue Creating a Table based on Macro's Parameter Name

[ Edited ]
Posted in reply to SteelersPitts

 

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.

View solution in original post


All Replies
Solution
2 weeks ago
Trusted Advisor
Posts: 1,934

Re: Issue Creating a Table based on Macro's Parameter Name

[ Edited ]
Posted in reply to SteelersPitts

 

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.

Occasional Contributor
Posts: 9

Re: Issue Creating a Table based on Macro's Parameter Name

Posted in reply to PaigeMiller

Thanks a lot Paige!

Super User
Posts: 19,878

Re: Issue Creating a Table based on Macro's Parameter Name

Posted in reply to SteelersPitts

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;

 

 

Occasional Contributor
Posts: 9

Re: Issue Creating a Table based on Macro's Parameter Name

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. 

☑ This topic is solved.

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

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