Hi SAS Community!
Happy new year to everyone!
I have a question that needs help from you. really appreciate it.
Now I have a SAS file with 500 lines of code plus 200 lines of comment.
Does anyone know how to delete all these comments by some quick method, instead of manually?
Is there any code or tool that I can leverage to complete this task for me, so that I don't need to manually look for comments and delete them by hand.
Thanks!
Hi @changxuosu,
If you're using the Enhanced Editor (i.e., the default program editor in a Display Manager SAS session under Windows) or some similar editor (perhaps in Enterprise Guide), you can use the familiar Replace dialog:
It's important to select the checkbox "Regular expression search" and to select "Find in comments only" from the "Find in:" drop-down list. Then you can use the period (.) -- the regular expression for "any character except carriage return" -- as the search expression, leave the "Replace with:" field empty and (if you're courageous) hit "Replace All".
This should remove all comments including the /* etc. characters -- with one exception: The percent signs of macro comments %* ... ;
So, if you have some of these, you may want to first replace the combination "%*" with a single asterisk (i.e., remove the % sign) using the Replace dialog without selecting the "Regular expression search" checkbox and with the "Find in code and comments" setting and then, as the second step, use the technique described above to remove the comments.
Hi @changxuosu,
If you're using the Enhanced Editor (i.e., the default program editor in a Display Manager SAS session under Windows) or some similar editor (perhaps in Enterprise Guide), you can use the familiar Replace dialog:
It's important to select the checkbox "Regular expression search" and to select "Find in comments only" from the "Find in:" drop-down list. Then you can use the period (.) -- the regular expression for "any character except carriage return" -- as the search expression, leave the "Replace with:" field empty and (if you're courageous) hit "Replace All".
This should remove all comments including the /* etc. characters -- with one exception: The percent signs of macro comments %* ... ;
So, if you have some of these, you may want to first replace the combination "%*" with a single asterisk (i.e., remove the % sign) using the Replace dialog without selecting the "Regular expression search" checkbox and with the "Find in code and comments" setting and then, as the second step, use the technique described above to remove the comments.
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.