BookmarkSubscribeRSS Feed
batu544
Fluorite | Level 6

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

2 REPLIES 2
Reeza
Super User

You need a macro 😞 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


 

batu544
Fluorite | Level 6
Thank you.. 🙂

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 1277 views
  • 0 likes
  • 2 in conversation