BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tfarkas
Obsidian | Level 7

UPDATED:

 

Within a PROC SQL step, I comment code using </* comment */>, like this;

 

 

proc sql;

create table comment_test as 

select *
from sashelp.cars
where make = 'Acura' /*filter by make*/

order by model; ; quit;

 

During development, however, I may want to comment out large sections of code, like the where statement in the above snippet.

 

proc sql;

create table comment_test as 

select *
from sashelp.cars
/*where make = 'Acura' /*filter by make*/*/
order by model; ; quit;

 

However, you'll notice that the right-hand, closing comment characters are now executable, so the step fails. 

 

A similar problem comes up if developing with, say, the data step. 

 

data comment_test;
set sashelp.cars; /* where make = 'Acura'; /* filter by make */*/
run;

 

Here, everything after the comment characters is commented out, so the run statement will not execute and the program fails.

 

The solution in the data step is to use <* comment ;> statements, rather than </* comment */>:

 

data comment_test;

    set sashelp.cars;
/*	where make = 'Acura'; * filter by make; */

run;

 

But this style of commenting is not available in proc sql. Try:

 

proc sql;

create table comment_test as 

select *
from sashelp.cars
where make = 'Acura'  *filter by make;
order by model;

;

quit; 

 

Can somebody please advise on a development workflow in proc sql that accommodates this issue?

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

One possibility is to use macro comments (start with %*) instead of normal comment lines (starting with *):

proc SQL;
  select *
  from sashelp.cars
  where make = 'Acura' %*filter by make; 
  order by model;
;
quit;

View solution in original post

10 REPLIES 10
Astounding
PROC Star

The simplest trick is to define the blocked-out section of code as a macro:

 

proc sql;
create table comment_test as
select * from sashelp.cars
%macro skip;
where make = 'Acura'; /* filter by make */
%mend skip;
;
quit;

Since the semicolon is part of the skipped code, you need to add one at the bottom of the SELECT statement in this particular case.

ballardw
Super User

@tfarkas wrote:

Within a PROC SQL step, I comment code using </* comment */>, like this;

 

 

proc sql;

create table comment_test as 

select *
from sashelp.cars
where make = 'Acura'; /*filter by make*/

quit; 

 

During development, however, I may want to comment out large sections of code, like the where statement in the above snippet.

 

proc sql;

create table comment_test as 

select *
from sashelp.cars
/* where make = 'Acura'; /*filter by make*/ */

quit; 

 

However, you'll notice that the right-hand, closing comment characters are now executable, so the step fails. 

 

A similar problem comes up if developing with, say, the data step. 

 

data comment_test;
set sashelp.cars; /* where make = 'Acura'; /* filter by make */*/
run;

 

Here, everything after the comment characters is commented out, so the run statement will not execute and the program fails.

 

The solution in the data step is to use <* comment ;> statements, rather than </* comment */>:

 

data comment_test;

    set sashelp.cars;
/*	where make = 'Acura'; * filter by make; */

run;

 

But this style of commenting is not available in proc sql.

 

Can somebody please advise on a development workflow in proc sql that accommodates this issue?

 

I "solve" this problem by not placing inline comments, always on a separate line and paying attention when block commenting code.

I also don't use the * text; comment.

This code runs fine on my system.

proc sql;
create table work.comment_test as 
select *
from sashelp.cars
/*where make = 'Acura';  *filter by make; */
 ;
quit;

I suspect the issue that made you think it wasn't available was that you included the semicolon that ends the create tableinside the commented text. So the quit wasn't properly recognized and left Proc SQL running.

tfarkas
Obsidian | Level 7

Yes, I've omitted a semi-colon! However, see my updated question. <* comment ;> does not work inside the select statement, so I'm left with the same problem. Am I still missing something?

Astounding
PROC Star

I already gave you one working solution.  Macro language is the better way.  But if you must have another solution that uses no macro language, omit the extra */ in this fashion:

 

proc sql;
create table comment_test as
select * from sashelp.cars
/* where make='Acura'; /* filter by make */
;
quit;

 The second /* becomes part of the comment.  The first /* begins the comment, and the final */ ends the comment.  It works, but it is less flexible since there could be many sets of embedded comments within the section of code that you want to skip.

 

The semicolon is needed, since the original semicolon is part of the comment.

ballardw
Super User

@tfarkas wrote:

Yes, I've omitted a semi-colon! However, see my updated question. <* comment ;> does not work inside the select statement, so I'm left with the same problem. Am I still missing something?


I don't know. Perhaps you are using EG or a SAS Studio version of some sort. Running in SAS Display Manager (or Foundation or Base)

186  proc sql;
187  create table work.comment_test as
188  select *
189  from sashelp.cars
190  /*where make = 'Acura';  *filter by make; */
191   ;
NOTE: Table WORK.COMMENT_TEST created, with 428 rows and 15 columns.

192  quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.05 seconds
      cpu time            0.01 seconds


runs just fine with the line comment you are having problems with (after adding the ; to end the Create table.

tfarkas
Obsidian | Level 7

Your code shows the comment after the SELECT statement is closed, which works fine for me too (I am using EG). If you try to comment the FROM statement, for example, the <* comment ;> syntax doesn't work, I don't think. Does it work for you?

Patrick
Opal | Level 21

@tfarkas 

The approach @Astounding suggested to you is what I'm using as well. It's an approach that just works for any code and comment combinations. I'm calling my "commenting out" macro normally "%macro null;"

%macro null;
   .... here all the code I don't want to execute
%mend;

 

PaigeMiller
Diamond | Level 26

In addition to the above, if you are needing to do this within a macro, you could use

 

%if 0 %then %do;
    ... code to comment out ...
%end;
--
Paige Miller
s_lassen
Meteorite | Level 14

One possibility is to use macro comments (start with %*) instead of normal comment lines (starting with *):

proc SQL;
  select *
  from sashelp.cars
  where make = 'Acura' %*filter by make; 
  order by model;
;
quit;
tfarkas
Obsidian | Level 7

This seems the best solution of those in this discussion for my purposes. The code does not get colored or highlighted as a comment (any way to change?), but the code will run fine with the inline macro comment, and chunks of code with inline macro comments can be commented out with <CTRL + />, which really facilitates development, IMO. Happy to hear dissenting opinions, though.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 10 replies
  • 5226 views
  • 0 likes
  • 6 in conversation