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?
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;
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.
@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.
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 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.
@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.
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?
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;
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;
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;
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.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.