DATA Step, Macro, Functions and more

Data step execution based on condition

Reply
Occasional Contributor
Posts: 5

Data step execution based on condition

[ Edited ]

Hi Everyone, 

 

I have a situation where I need to run different data step based on output from 1st PROC SQL. I was looking for GOTO statement but it will not help because it needs to be used inside one data step. 

 

PROC SQL 
        query to get the details from DB2 table. 
QUIT;
DATA _NULL_;
 if &sqlobs = 0 
      I need to bypass below proc steps and execute the code from label XXXX

run; 

proc sort data=xxx;
run;

proc SQL 
   another query to get data from DB2 
quit;

DATA ABCD;
SET AAAA ( KEEP=XX,YY,ZZ,...);
few logics here.. run;
XXXX: proc SQL get data from DB2 table for another processing quit; proc print; ... ...

Any suggestion will be really helpful. 

 

 

Thank you

pk

Super User
Posts: 23,247

Re: Data step execution based on condition

You need a macro Smiley Sad But, it's a pretty basic one. 

 

Here's a fully worked example that is from the SAS documentation. It checks if a data set has observations and prints it or otherwise prints a message to the log. 

 

http://documentation.sas.com/?docsetId=mcrolref&docsetTarget=p011imau3tm4jen1us2a45cyenz9.htm&docset...

 

It's fully explained so its a good starting point. But, if you have any further questions, feel free to post back. 

 

Full list of macros in the appendix (for reference):https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Ap...

 


batu544 wrote:

Hi Everyone, 

 

I have a situation where I need to run different data step based on output from 1st PROC SQL. I was looking for GOTO statement but it will not help because it needs to be used inside one data step. 

 

PROC SQL 
        query to get the details from DB2 table. 
QUIT;
DATA _NULL_;
 if &sqlobs = 0 
      I need to bypass below proc steps and execute the code from label XXXX

run; 

proc sort data=xxx;
run;

proc SQL 
   another query to get data from DB2 
quit;

DATA ABCD;
SET AAAA ( KEEP=XX,YY,ZZ,...);
few logics here.. run;
XXXX: proc SQL get data from DB2 table for another processing quit; proc print; ... ...

Any suggestion will be really helpful. 

 

 

Thank you

pk


 

Occasional Contributor
Posts: 5

Re: Data step execution based on condition

Thank you.. Smiley Happy
Ask a Question
Discussion stats
  • 2 replies
  • 142 views
  • 0 likes
  • 2 in conversation