0

I need to produce the report from the sas dataset t_final_Summary. When I use
the proc report or proc tabulate I won't get the rows for those where column
does not have the value in them. So, I created a new dataset named Expiring
with same columns as in the report.

The t_final_Summary has columns named--Sub_LOB,Group,Mat_Month and Comm_Incl. I am trying to pass the value of the macros from that table to another table
named Expiring which has the columns named Sub_LOB, Group,Sum_of_Comm_Incl for
varying Mat_month. I wrote the following code:

%macro mat (sub,grp,mth,MCRO);
  proc sql no print;
    select case 
             when Sum(Comm_incl)=. then 0 
             else sum(Comm_Incl) 
           end format=16.2
      into :&MCRO. 
      from t_final_Summary 
     where Sub_LOB= "&sub." 
           and Group="&grp." 
           and Mat_Month="&mth.";
  quit;
%mend mat;

%mat(CRE Commercial, Carolina Group, _Expired, goid);

/*Now I want to check my macro variable goid using %put*/ 
%put &goid;

Then the log always tells me that the macro goid is not resolved. Is there any
error in the macro statements. I could not figure out. Can anyone help me please?

Dominic Comtois
  • 10,230
  • 1
  • 39
  • 61
shankar
  • 63
  • 1
  • 8
  • Did you try PRELOADFMT as suggested? – Reeza Dec 20 '16 at 04:17
  • Macro variable scope - variable dies not exist outside of macro. Definitely a duplicate in both respects for this question. – Reeza Dec 20 '16 at 04:19
  • Possible duplicate of [How to create a macro variable within a macro?](http://stackoverflow.com/questions/38361696/how-to-create-a-macro-variable-within-a-macro) – Reeza Dec 20 '16 at 04:58
  • I might not get exactly what you're asking, but are you aware of the `missing` option for those procs? If not, well this might just be it... – Dominic Comtois Dec 23 '16 at 04:52

1 Answers1

0

Since the rest of your macro seems correct, I am only addressing how to get a parameter to resolve as a macro variable. The macro variable needs to be made global prior to passing it to the macro.

Code:

%Macro Testit(received_var);

 Proc sql noprint;
  Select make into :&received_var from sashelp.cars where make="Acura";
 Quit;

 %Put Received_Var(Local): &&&received_var;

 %mend;

 %Global Passed_Var;
 %Testit(passed_var);

 %Put Passed_Var(Global) : &passed_var;

Log:

24             %Macro Testit(received_var);
25         
26              Proc sql noprint;
27               Select make into :&received_var from sashelp.cars where Make="Acura";
28              Quit;
29         
30              %Put Received_Var(Local): &&&received_var;
31         
32              %mend;
33         
34              %Global Passed_Var;
35              %Testit(passed_var);
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


Received_Var(Local): Acura
36         
37              %Put Passed_Var(Global) : &passed_var;
Passed_Var(Global) : Acura
Jay Corbett
  • 28,091
  • 21
  • 57
  • 74
  • Yes you are right. The macro should be global before passing it to the macro in proc sql. Thank you very much for your help – shankar Jan 10 '17 at 01:51