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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 1000 views
  • 0 likes
  • 2 in conversation