I have created a macro (supp_waterfall) which is used to calculate the number of records dropped (RecDrop) at every suppression step. There are 16 suppression steps so the macro will be executed 16 times.
The goal is to create 16 macro variables holding 16 drop counts. But I am not sure how to create and keep these 16 macro variables and their values. I would like to use them to calculate the drop total later in the program.
Below is the portion of the code related to the drop count variable:
%macro supp_waterfall (supp_file, supp_out, numstart, rptorder);
/*pass in the input file, output file, record begin, report order */
if _n_=1 then do;
RecDrop is the variable I would like to keep for each of the 16 times this macro is executed. I have no idea how to create a macro variable for it so I tossed in the 'call symput' in there. I get syntax error for it.
I attached '&rptorder' to the end of the variable DROP as an unique identifier for the 16 drop counts. So &rptorder goes from 1 to 16. rptorder is hardcoded and passed into the macro. Everything works except the CALL SYMPUT statement, which gives me a syntax error.
I hope i have given enough information for anyone to trouble shoot. Any suggestions will be greatly appreciated.
Suggest you run your code with the following to get the most diagnostics output:
OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT;
First, you are going to have issues when you do not code a RUN statement to let SAS compile up to the point in your code.
But, also, you are not incrementing &rptorder anywhere in code you have shared. I would expect this component to be most important.
Without details (which are also important for forum replies), it's likely you are getting some macro variable error or macro compilation error.
Lastly, you show a macro supp_waterfall being invoked but with macro variables being supplied to the macro invocation -- again, we don't see what leads up to the subordinate macro invocation, which is critical for decent feedback and guidance without guessing or speculating too close to the margin.
Recommend you implement the suggestion OPTIONS statement, run your code a few times, possibly even setup your code-path without the "help" of macro processing - this suggestion helps validate that you have a workable program flow before introducing the macro language challenges. So, some self-directed desk-checking with no macro, then maybe go macro and again more testing with max diagnostics turned on for effect, and follow the program flow. If you then have issues or concerns, re-post a reply with copious SAS log output diagnostics and warnings / errors intact so others can assist your quest.
My code has the OPTIONS and the RUN statements as you suggested. I did not include them at the beginning of my post to reduce the size of it. The increments are working fine. For clarification purposes, here is the code that evokes the macro at the second step:
Suggest you share all of your code and preferably within a SAS execution session to help with anyone's debugging - also, you may want to consider inserting statements like (you assign unique nnn value for each putlog referenced):
putlog '>diag-nnn>' / _all_;
These helpful diagnostics will generate SAS data step variable values along the way with your program.
Also, here's another that will help you:
Frankly, it's guess-work without suitable code and preferably after SAS log generated messages for helpful reference, both to yourself and the forum readers.
The first time the macro gets executed the value of Drops is 'Drops 1'.
My goal is to have a variable at the first step called 'Drops1' with the value of 1203 (the drop count). How would I change this code to assign the value 1203 to the variable Drops1?
I still didn't get what you are trying to do, but...
drops = 'Drop'||&rptorder;
will result on assigning the value of the RecKept dataset varialbe to the macro variable named Drops.
If you are trying to assign a value to a macro variable which the name corresponds to the value of the dataset variable Drops, you should do it the following way (I'm assuming that the macro variable rptorder resolves to: 1):
drops=cats('Drop',"&rptorder"); * concat Drop&rptorder and trim blanks;
If rptorder resolves to a dataset variable name, just remove the double quotes around it.
This will assign the value of the dataset variable RecKept to the macro variable named Drop1.
I agree with Peter. I'm still not convinced you need a macro program. Also, I'm not sure what you want to do with your CALL SYMPUT, but one of the rules of macro programming is that you cannot CREATE a macro variable with CALL SYMPUT and then USE that same macro variable in the same data step program. A step boundary has to occur before you can USE the macro variable that was created with CALL SYMPUT.
So, depending on your design and what you want to do and your other statements in the macro program, you might have issues with the macro variable that you're trying to create. ... IF you need a macro program at all.