SAS Programming

DATA Step, Macro, Functions and more
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-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1616 views
  • 0 likes
  • 2 in conversation