Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

if no errors write output file - if error create empty file    - SAS 9.2

Posted on 2013-12-17
1
Medium Priority
?
600 Views
Last Modified: 2013-12-18
Experts,

I have a file that has four columns I am checking to see if there is an error.
if start_date_error = 'X' or
        end_date_error = 'X' or
          residual_start_error = 'X' or
             residual_end_error = 'X' or
               lob_error = 'X' or
                 media_type_error = 'X'  or
               dnis = . then   ..............................

If one of the above conditions is true for any record on the file, I do not want to write an output file.  If none of the records have an error, I would like to write an output file.

Can someone tell me if there is a way to do this?

The challenge is all records from the file need to be tested before the decision can be made to create an output file or an empty file.
0
Comment
Question by:morinia
1 Comment
 
LVL 14

Accepted Solution

by:
Aloysius Low earned 2000 total points
ID: 39725504
this can only be accomplished in 2 steps:
step 1 scan through the entire dataset:
data _null_;
  set [source data] end = eof;
  retain haserror; /* any variable you like to name it */

  if _N_ eq 1 then haserror = 0; /* if first record initialize to 0 */

  haserror = [all your conditons]; /* as long as the conditions return a TRUE, then haserror will hold the value 1 else haserror will continue to hold the value 0 because of the retain statement */

  if eof then do; /* reached the end of dataset */
    call symput("haserror", haserror); /* set the last value of haserror into a global variable named haserror - again it's up to you to name it */
  end;
run;

step 2 write a macro to determine the next step to take:
%macro donext;
  %if &haserror eq 1 %then %do;
    [code to create empty file]
  %end;
  %else %do;
    [code to create output file]
  %end;
%mend;
%donext;
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I was talking with Tim Sharp, one of my colleagues from our Technical Account Manager team about MongoDB’s scalability. While doing some quick training with some of the Percona team, Tim brought something to my attention...
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

927 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question