Solved

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

Posted on 2013-12-17
1
577 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

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
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…
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…

623 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