Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2013-12-17
1
Medium Priority
?
588 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 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

670 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