BookmarkSubscribeRSS Feed
djrisks
Barite | Level 11

Hello,

 

I would like to know the regular expression I can use to match comments please? Such as /* This is a comment */

I would like to replace the comment with just this text "/* */" in order to save space within my variable.

 

Below is the code that I've been trying to use, just to see if I can match the opening of the comments tag, but I'm not sure how to do it.

 

without_comments = prxchange("s//\*\w+)/ /", -1, with_comments);

You're help will be greatly appreciated.

 

Thank you!

 

Kriss

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Sorry, what do you mean by:

"I would like to replace the comment with just this text "/* */" in order to save space within my variable."

Comments are not in a variable, they are in code.  Are you storing code in a dataset or something, why?

As for replacing it, comment could be anything.  Comes down to code parsing which isn't a simple matter.  // is also a comment, /* could go over mutiple line.  Various other things to bear in mind also.  

djrisks
Barite | Level 11

Hello RW9. I'm calculating CTC grades for laboratory results, and so the algorithms along with the comments are within my variables. I'm using this alongside call execute. 

 

I've seen a potential solution on this site, which goes over the things you have mentioned, i.e comments on multiple lines. I'm just trying to incorportate this into SAS.

 

http://blog.ostermiller.org/find-comment

 

Many thanks,

djrisks
Barite | Level 11

I've seen that this code can be used to match comments. Which is similar to what that website had. I just had to escape the forward slashes too. For my example, I can just use this simple case below. Because it does find the majority of my comments (if not all). I think when the results are in the dataset there may not be the issue of comments being on multiple lines.

 

pattern = prxparse("/\/\*.*\*\//");

 

Thanks for you help.

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
  • 3 replies
  • 1039 views
  • 0 likes
  • 2 in conversation