DATA Step, Macro, Functions and more

Need to break from a data step with a return a code

Accepted Solution Solved
Reply
Contributor
Posts: 32
Accepted Solution

Need to break from a data step with a return a code

Hi,

 

I am executing my SAS pgms in unix environment, so executes the .sas pgms in shl.

Now i have a requirement to break a datastep on a particular condition & return a code to shl, so that based on the return code shl will call a sql loader which loads data to oracle table.

 

data header;
infile "<path>/data.dat" dlm="|";
input recds : $2.
id : 18.
name : $30.
chk_flg : $1.;

if(chk_flg) = 'Y';
then <the pgm needs to break with a return code>

 

run;


Accepted Solutions
Solution
4 weeks ago
Regular Contributor
Posts: 190

Re: Need to break from a data step with a return a code

Try using ABORT RETURN - the documentation is here

View solution in original post


All Replies
Solution
4 weeks ago
Regular Contributor
Posts: 190

Re: Need to break from a data step with a return a code

Try using ABORT RETURN - the documentation is here

Super User
Super User
Posts: 7,421

Re: Need to break from a data step with a return a code

Personally I find the whole breaking out of programs to be not a good methodology.  Code should run fully and then return its final value and outputs at all times.  

A question for you, which jumped to mind with the above in mind, I am sure (and its been years since I used it) Unix has string find utilities and such like, so why do you need to read the file into SAS, check for a string, and then jump back to the operating system.  Can all this not be done directly in the OS scripting?  Even better would be to get a file which is directly usable rather than finding strings.  It just seems to be using SAS for the sake of using it.

Contributor
Posts: 32

Re: Need to break from a data step with a return a code

Ok so to answer to your 2nd part, we have a process in place which already uses SAS pgm & run it to completion. The SAS pgm checks few columns(its a validation of data pgm). Now the there is a new requirement which is the file will be submitted at the same path(if the file arrives at the path, the already existing pgm triggers), same file name, only addition is an extra column in header. If we read that SAS dont have to do anything. Hope this makes sense.

Super User
Posts: 6,969

Re: Need to break from a data step with a return a code

Given that you have UNIX, I'd solve that with the cut and grep utilities directly from the shell:

if cut -f3 -d'|' filename|grep Y>/dev/null
then
  #execute as wanted
else
  #put message
fi

 

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 164 views
  • 1 like
  • 4 in conversation