Solved

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

Posted on 2013-12-17
1
562 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 500 total points
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Creating and Managing Databases with phpMyAdmin in cPanel.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
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…

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now