DATA Step, Macro, Functions and more

Summary output table

Reply
N/A
Posts: 0

Summary output table

I need to create a driving program, that runs individual programs and produces output sas dataset, that contains just 3 variables - Edit check name, Edit check description and Number of errors.
SAS Super FREQ
Posts: 8,743

Re: Summary output table

Hi:
You may want to check out some examples of using either a simple %Include statement or a full-fledged macro program to invoke individual macro programs.

For example, you might have this program called DRIVER.SAS:
[pre]
libname wombat 'c:\temp\wombatdir';

%include 'c:\My Programs\readdata.sas';
%include 'c:\My Programs\bkupdata.sas';
%include 'c:\My Programs\makefile.sas';
[/pre]

In the above example, you would submit the DRIVER.SAS program and then you would submit this program. First, the LIBNAME statement would be issued and then the READDATA.SAS program would be included and sent to be executed. When that was done, the BKUPDATA.SAS program would be included and sent to be executed. And, finally, the MAKEFILE.SAS program would be included and sent to be executed. That's a very simple example.

Or, you could define 4 separate macro programs and store some or all of them in a Macro autocall library. Let's say the macro programs were named:
%READ1, %BKUP2, and %MAKE3
. Then you might define and execute a 4th macro program called %DRIVER, like this:
[pre]
%MACRO DRIVER;




%READ1;



%BKUP2;



%MAKE3;



%MEND DRIVER;
[/pre]

The above code only DEFINES the %DRIVER macro program. To invoke the program, you would need to submit the invocation as:

%DRIVER;


and, then, the code inside the macro program would be sent the macro processor to have all the macro references resolved and then the resolved code would be sent to SAS to be compiled and executed.

To learn about the difference between a simple %INCLUDE statement and a Macro program, you should consult the SAS Macro Reference documentation.
%INCLUDE: http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a000214504.htm
Macro Reference: http://support.sas.com/documentation/cdl/en/mcrolref/59526/HTML/default/a002293969.htm

cynthia
N/A
Posts: 0

Re: Summary output table

Hi, thans for quick feedback. My summary sas dataset/table should be like this after all edit checks ran:
----------------------------------------------------
Edit | Description | # Errors |
----------------------------------------------------
123 | sex is missing | 0 |
----------------------------------------------------
124 | date is missing | 12 |
----------------------------------------------------

Can you give me a hint, please, what should I put in or out of this macro to have all 3 variables:

%macro err (dat = _last_, edit= ,errfile= , errdesc= );
proc contents data = &dat out = xnumerr noprint;
data _null_;
set xnumerr;
if _n_ = 1;
call symput('xnumobs',left(nobs));
run;


%mend err;

%include "123.sas";
%err( edit=123, errdesc=SEX IS MISSING);

%include "124.sas";
%err( edit=124, errdesc=DATE IS MISSING);
SAS Super FREQ
Posts: 8,743

Re: Summary output table

Hi:
My only hint is that you should never start to code a macro program from "scratch" -- that's why I didn't show any real code in my program shells above.

My theory of how to write a macro program is that there are 4 basic steps, especially when you're getting started.

1) Have a WORKING SAS program that does what you want for one instance or one occurence or one file before you do ANYTHING with SAS macro code.

Then, once you have #1, figure out where you can use macro variables to make the program more generic.
2) Test your theory by substituting macro variable references for items in your code (like data set names, variable names, titles, etc). Then use %LET to assign test values to the macro variables to see whether the program still works with just macro varible references.

Then, once you have #2 working, move onto #3 and
3) make a macro program by using the %MACRO/%MEND around the portion of your code that you want to invoke multiple times. Turn your %LET-statement macro variables into macro parameters. Make sure that you can invoke this macro program correctly and that you get the correct results for one invocation before you move onto #4.

4) NOW introduce macro conditional logic and/or macro %do loops into the code and test your macro program to make sure that it generates ALL the output your want or reads ALL the files you want.

I do not see your working SAS program. When you use PROC CONTENTS to create an output dataset with contents information the NOBS variable contains the number of observations in the dataset -- this is the total number of rows. So, for example, you can have a dataset with 100 rows, but 50 of those rows might have mssing values for AGE -- PROC CONTENTS is going to show you 100. Therefore, your macro variable &XNUMOBS is going to be the total number of observations in _LAST_, NOT the total number of errors for a variable.

With the code snippet below, I feel like I've come into the middle of the movie. Where is the file _LAST_ coming from?? the program 123.sas??? Is it creating an output data set that only contains missing values? It's sort of hard to figure out.

But if program 123.sas is doing the edits then there may be no need for the %ERR macro program at all. You could just have program 123.sas make you an output dataset -- it already knows or can count how many "error" rows there are and can create an output dataset that you could append to an overall error file.

It is possible that each of your "editing" programs could create an error file at the time each file is being edited. Then if all your error files had the same variable names, you could simply append them all together or even do a simple proc print of each one.

To me it seem the key to what you want to do is in the programs you are running before you run the %ERR macro program.

cynthia
Ask a Question
Discussion stats
  • 3 replies
  • 128 views
  • 0 likes
  • 2 in conversation