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

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!

 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

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:

replace_dialog.png

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.

View solution in original post

7 REPLIES 7
Reeza
Super User
Why would you delete all your comments?

Is a particular standard used in your program? Are all the comments the same type, ie *; or /**/ or %*;

Are all comments separated from code, or can they be embedded in the code as well?

eg of separated:

*this calculates summary statistics;
proc mean data=sashelp.class; run;

*this is embedded;
proc mean data=sashelp.class /*input data set*/
N Mean NMISS /*control statistics displayed*/
;
run;
changxuosu
Quartz | Level 8
Thank you so much for your reply. This SAS file contains complicated data cleaning process using multiple data sources. I want to collect all raw variables used in this data sources. Due to the complexity of this SAS file, it is very tortuous for me to find out these variables used in naive and manual way. So I was trying to use Python to scrape certain variables. This would require me to input the giant SAS code as a string into Python with all comments removed. These comments are mostly standalone, separated from code (thank you for pointing out these question). hope this makes sense.
Reeza
Super User
I don't have time to get into this at the moment, but check out PROC SCAPROC and search on lexjansen.com for log parsers which can help with what you're trying to do as well. If your data is hitting a server, there may be some other ways to get this info as well.
changxuosu
Quartz | Level 8
thank you so much Reeza, the "Proc Scaproc" you mentioned opened a new door for me! thank you so much for knowledge sharing, I really really really appreciate it!
changxuosu
Quartz | Level 8
Hi Reeza, I looked into PROC SCAPROC, it's very powerful to analyze code to extract information such as input dataset, output dataset, leveraging the /* JOBSPLIT */ comment. However, I don't know how we can extract variable names using text file produced by PROC SCAPROC. Any ideas, inputs, suggestions are greatly appreciated.
FreelanceReinh
Jade | Level 19

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:

replace_dialog.png

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.

changxuosu
Quartz | Level 8
wow! amazing! i can never think of this smart trick by myself until seeing your post! thanks a lot! Really appreciate it! I really feel the positive emergy coming from SAS community

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 7 replies
  • 1001 views
  • 7 likes
  • 3 in conversation