I have a dataset called DataSetA which has n observations. I have a smoothly running sas programme called ProgB. ProgB takes one observation at a time of DataSetA, beginning with the first one, does a whole bunch of stuff and updates DataSetB with a new record or changes an existing record. What I want to do is execute ProgB once for each observation of DataSetA. I am doing this manually at the moment by changing a macro variable, which is the observation number of DataSetA: manually updating the observation number: 1, 2, 3, ...,n and manually pressing the SAS programme execution button each time. I would like to automate this simple process, but I don't know how. Could you please help me?
I use PC SAS. I looked at some available tutorials and tips on SAS macros and functions, but I am overwhelmed by all the information for what I think is a really simple automation task. I have read that macros and functions cannot accommodate data steps, even the rather simple ones that I have in my ProgB (but I could be wrong). Any tips on what I can do?
Algorithmically, all I want do is:
Do i = 1 to n;
GetNextDataSetAObsvn(i); /* puts DataSetA observation i in a table with only one observation */
ExecuteProgB; /* executes lots of data steps, procs, etc on this single obsvn and updates DataSetB with the result */
But I don't know how to do this in PC SAS, even after trying for many hours!
In particular, look at some of the later examples (Steps 7, 8, and 9), which show how to automate a DATA step and a PROC step in a macro program. Of course, you will have to understand steps 1 through 6 - -but the examples are quite good and very easy to understand.
> This is an excellent paper to get you started:
Many thanks for the paper reference. I worked through all the examples and learned a lot more from it than many other papers I looked at because this one was really step by step. Combining what I learned from this paper with the other reply I got, I have been able to solve my problem after more than a month of work on it! Thanks very much for your fast response and help!
If I understood you correctly this is what you need (I used SASHELP.CLASS as an example);
set &dsn obs=n end=e;
if e then call symputx('n',n);
%do i=1 %to &n;
> %let dsn=SASHELP.CLASS;
> %macro a;
> data _null_;
> set &dsn nobs=n end=e;
> if e then call symputx('n',n);
> %do i=1 %to &n;
> data _a;
> set &dsn;
> if _n_=&i;
> %mend a;
Many many thanks for your generous help on my problem! Combined with the paper Cynthia referred me to and your suggested code, it worked brilliantly! I solved a long-standing issue I had and learned a great deal more about macros.
Thanks so much! and also for the how fast you responded!!