Hi:
I get a bit nervous when I see code to delete metadata objects -- especially if that code contains macro references that just plain won't work.
My "rules" of macro programming are:
1) have a working SAS program that does NOT use macro variables at all -- know what the correct code is to perform your task. Test and make sure that that code works, and does not generate ANY errors in the SAS log and that you do not have any logic errors in the output. Then and only then, move on to step 2.
2) write a generic version of your program, using &MACVAR references and %LET statements for a few test cases, where possible, to make sure that your program will work with Macro variable references. Check things like whether you have double quotes in the right places and that your macro variables are resolving correctly, that numbered macro variables are being built and resolved the right way. Make sure that all your generated code is syntactically correct and that you don't drop semicolons or lose pieces of statements. After #2 version of the program is working, then move to #3.
3) You may be done after #2 -- if you do not need to use any macro-specific language constructs. If you can get by with %LET or CALL SYMPUT or SELECT INTO to build your macro variables, then there's no need to build a macro program. But, if you need macro %IF conditional logic or macro %DO loops or other kinds of things that can only be done in a macro program, then define your macro program with %MACRO/%MEND statements and be sure that you have correctly identified all the parameters that the macro program needs to run properly and then test this macro program by invoking it for all your possible test cases. Then,
4) decide how you're going to run your macro program, as a session compiled macro program, as an autocall macro program or as a stored, compiled macro program and put that version of the program in place and then test again.
It seems to me that you are still in the stage before rule #1 -- you do not have a working SAS program WITHOUT any macro variables -- so it's nearly impossible to make recommendations for how to convert your program to use macro variables -- if you even need a macro program or macro variables at all.
First, when you create a macro variable, as you do with the call symput, that macro variable would not be available to you until AFTER the program in which the macro variable was created. In other words. If you hope to use &i, it would have to be after the step boundary of the data step program in which &i was created. Generally, folks use data _null_ and call symput because they want to do something like this:
[pre]
data _null_;
set sashelp.class end=eof;
if age ge 15 then teentot + 1;
if eof then do;
call symput('numteens',put(teentot,2.0));
end;
run;
ods listing;
option nodate nonumber nocenter;
proc print data=sashelp.class noobs;
title "There are &numteens students who are eligible for driver training.";
run;
[/pre]
&NUMTEENS is created in the data _null_ program, but I cannot use &NUMTEENS inside THAT data step program. In this example, I am using it in a TITLE statement after the RUN statement that ends the DATA _NULL_ program. If I tried to referene that macro variable inside the data step program, I should get this warning:
[pre]
WARNING: Apparent symbolic reference xxxxxxxx not resolved.
[/pre]
where xxxxxxxx is the name of the macro variable that I just created in the CALL SYMPUT.
There's also the issue of your reference to &ids&i -- it's probably not the correct reference. If you were referencing numbered macro variables, then there are a couple of macro variable rules regarding building references ...
the "forward scan" rule and the "rescan" rule that generally dictate that you refer to your numbered macro variables as: &&macvar&i -- which allows the delay of the "front" half of the macro variable from resolving while the "back half" resolves to a number. &&macvar&i would resolve to &macvar1 and then &macvar1, when it is rescanned, would get looked up in the global symbol table.
Whether you need to do anything in a macro program at all is anybody's guess. My recommendation would be to contact Tech Support for help instead of trying to figure out how to delete metadata objects AND how to code macro variable references at the same time.
One thing about SAS datasets that is important to remember is that the SAS DATA step progam is an implied loop... so, if you had this code:
[pre]
data newclass;
set sashelp.class;
newvar = sum(age, height,weight);
run;
[/pre]
Then the variable NEWVAR would be calculated for EVERY observation in SASHELP.CLASS. That's why several people have pointed out that if you have your IDs in a SAS dataset, there may not be a need to load them into numbered macro variables at all.
You have also referred several times to the numbered macro variables as being in an "array" or having a "dimension". I know there are some user group papers out there that use this terminology to refer to macro variables, but I don't like it and I don't agree with that representation. Numbered Macro variables are not an ARRAY structure in the true sense of an ARRAY as a data structure. The macro variables live in memory, in their GLOBAL or LOCAL symbol table and they could just as well be called &FRED, ÐEL, &LUCY and &RICKY as easily as they could be called &MACVAR1, &MACVAR2, &MACVAR3 and &MACVAR4. (In fact, SAS arrays are not actually permanent data structures, either -- they only exist for the duration of the program which has an ARRAY statement -- but that's a whole other topic for discussion.)
The value of having numbered macro variables, however, is so you could use them within a %DO loop -- which is a language construct that is only allowed in a Macro program -- when you use a %DO loop, then, your "counter" variable automatically becomes a macro variable that you can use to reference within the %DO loop (without a CALL SYMPUT). It is used in a completely different way than the DATA step DO loop and the two forms of iterative processing should not be confused.
If you really want to learn about the SAS Macro facility, which is a totally cool part of SAS, then a few places to start would be the Macro documentation, books by users on the SAS Macro facility or user-group papers on the SAS Macro facility -- like this one:
http://www2.sas.com/proceedings/sugi28/056-28.pdf
Since you will need to use the macro facility -someday-, at the bottom of this posting is a complete macro program and invocation that you can copy and run. Study the results in the SAS log carefully and with the results from the PROC PRINTS. This is just one example of using a macro program to generate repetitive code. I could just as easily use a macro program to generate one statement in a program or one piece of one statement.
I'm not sure that you need the macro facility right now -- either macro variables or a macro program -- for your stated purpose. Again, I advise you to contact Tech Support for more help.
cynthia
[pre]
** start the macro definition phase;
%macro prtprod;
proc sql noprint;
select count(distinct prodtype) into :numrows
from sashelp.prdsale;
%let numrows=&numrows;
%put -------> numrows is &numrows;
select distinct prodtype into :pt1-:pt&numrows
from sashelp.prdsale;
quit;
** This PROC SQL step has done 2 things;
** 1) found the count of distinct PRODTYPE values and;
** 2) put those values into numbered macro variables;
** what are the values in the macro variables?;
%do i = 1 %to &numrows;
%put -----> # &i;
%put -----> For pt&i -- PRODTYPE is: &&pt&i;
%put ----->;
%end;
ods listing close;
options nodate nonumber nocenter;
** now build proc print code for every value;
** of PRODTYPE, as stored in pt1-pt&numrows;
%do i = 1 %to &numrows;
%put Starting PROC PRINT;
ods html file="c:\temp\&&pt&i...html" style=sasweb;
proc print data=sashelp.prdsale(obs=10);
title "I is &i -- Prodtype is: &&pt&i " ;
where prodtype = "&&pt&i";
run;
ods html close;
title;
footnote;
%end;
ods listing;
** another way of using a Macro DO loop;
%put Starting ODS HTML for alternate report;
ods listing close;
ods html file="c:\temp\OneReport_TwoPrints.html"
style=sasweb;
%do i = 1 %to &numrows;
proc print data=sashelp.prdsale(obs=5);
title "I is &i -- Prodtype is: &&pt&i " ;
title2 '%DO loop is inside ODS sandwich';
where prodtype = "&&pt&i";
run;
%end;
ods html close;
ods listing;
title;
footnote;
%mend prtprod;
** end the macro definition phase;
***************************************;
***************************************;
** NOTHING happens until the ;
** Macro program is invoked;
** turn on debugging options;
options mprint symbolgen mlogic;
**Now, invoke the macro program just defined;
%prtprod;
** turn off debugging options;
options nomprint nosymbolgen nomlogic;
title; footnote;
[/pre]