Solved

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

Posted on 2013-12-17
1
572 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 14

Accepted Solution

by:
Aloysius Low earned 500 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Azure Functions is a solution for easily running small pieces of code, or "functions," in the cloud. This article shows how to create one of these functions to write directly to Azure Table Storage.
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…

738 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