<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Removing Comments in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359576#M274534</link>
    <description>&lt;P&gt;The simplest method - and bearing in mind you need to evaluate multiple assignments and such like for instance in one file abc might be c:\dir1, in another program it might be c:\dir2, so an automatic approach might not work - would be to take a copy of SASHELP.VLIBNAME, run the programs i.e. %include, then just take a list of SASHELP.VLIBNAME not in your copy:&lt;/P&gt;
&lt;P&gt;E.g:&lt;/P&gt;
&lt;PRE&gt;data temp;
  set sashelp.vlibnam;
run;

libname abc "s:\temp\rob";

proc sql;
  create table WANT as
  select * from SASHELP.VLIBNAM 
  except select * from TEMP;
quit; 

libname abc clear;&lt;/PRE&gt;
&lt;P&gt;This will create want with one row for the libname I just created with name and path. &amp;nbsp;Far simpler than re-implementing a text parser to &amp;nbsp;work out what is what - note it wont pick up on duplicates however!&lt;/P&gt;</description>
    <pubDate>Thu, 18 May 2017 09:06:05 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-05-18T09:06:05Z</dc:date>
    <item>
      <title>Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359511#M274529</link>
      <description>&lt;P&gt;Hi Guys,&lt;/P&gt;&lt;P&gt;I have an input sas program where i have all my libnames declared.I am reading that into a sas dataset.while doing that its reading commented out values too.And i don't want those commented code into my sas dataset.&lt;/P&gt;&lt;P&gt;I would like to remove the comments from my dataset whether the comments &lt;STRONG&gt;are made in one single line or multiple lines.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;the code looks like this:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Libname sample1 "XYZ";&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Libname sample2 "ABC";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/*Libname sample3 "asdfghjj";*/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Libname sample4 "uxcvdgh";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;/*commented out&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Libname sample5 "XYZasdf";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Libname sample6 "XYZasdfgb";**/&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Libname sample7 "XYZdefrgevsdc";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Requirement:&lt;STRONG&gt;Without editing the source file i.e., above sample code i would like the output like this in sas dataset:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;obs var1&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;STRONG&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/STRONG&gt;&lt;/SPAN&gt;Libname sample1 "XYZ"&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;Libname sample2 "ABC"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3 &amp;nbsp; &amp;nbsp; &amp;nbsp;Libname sample4 "uxcvdgh"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;4 &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;Libname sample7 "XYZdefrgevsdc";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks For the Help&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 23:05:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359511#M274529</guid>
      <dc:creator>User12</dc:creator>
      <dc:date>2017-05-17T23:05:19Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359515#M274530</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
  input STATEMENT $80.;
cards4;
Libname sample1 "XYZ";
Libname sample2 "ABC";
/*Libname sample3 "asdfghjj";*/
Libname sample4 "uxcvdgh";
/*commented out
Libname sample5 "XYZasdf";
Libname sample6 "XYZasdfgb";**/
Libname sample7 "XYZdefrgevsdc";
;;;;
run;

data WANT;
  set HAVE;
  if STATEMENT =:'/*' then COMMENT+1;
  if not COMMENT then output;
  if reverse(trim(STATEMENT))  =:'/*' then COMMENT=0;
  keep STATEMENT;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 23:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359515#M274530</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-05-17T23:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359516#M274531</link>
      <description>&lt;P&gt;I don't know if that's possible, at least not without &lt;EM&gt;some&lt;/EM&gt; modifications to the source file, although I'd be interested to be proven wrong. (Edited to Add: Proven wrong before I even finished posting, that's gotta be a record! Interesting code&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;, I'll have to remember that.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the bigger question is why do you need to import your SAS code into a dataset? &amp;nbsp;What are you actually trying to accomplish?&amp;nbsp;&amp;nbsp;If my assumption is correct and it's something other than just having a dataset containing parts of your SAS code, there may be a better way to go about it.&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 23:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359516#M274531</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2017-05-17T23:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359520#M274532</link>
      <description>&lt;P&gt;hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/56496"&gt;@Sven111&lt;/a&gt;&amp;nbsp; i have multiple files where mt libnames are declared.i want to store all of them in one single dataset to keep track of the locations&lt;/P&gt;</description>
      <pubDate>Wed, 17 May 2017 23:54:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359520#M274532</guid>
      <dc:creator>User12</dc:creator>
      <dc:date>2017-05-17T23:54:08Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359525#M274533</link>
      <description>&lt;P&gt;Are they ones you use on a regular basis or more long-term ones that you just want to track? &amp;nbsp;If it's the former you could just declare them once in your SAS autoexec file so they'll be setup for whatever code your running, I have several LIBNAMES setup like that in my autoexec so I can easily reference them from EntGuide or base SAS. &amp;nbsp;If it's for long-term tracking I still think a dataset isn't necessarily the best way to go, honestly I think just maintaining them in one or more text files may be better and more flexible. &amp;nbsp;You could even source them using an %INCLUDE statement later on if you wanted to call them again. &amp;nbsp;It's not as automated, but unless you're dealing with hundreds or thousands of LIBNAMES it's probably the way I'd go. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Plus while&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;'s code handles the examples you've provided very well, as it stands I doesn't look like it will be able to detect comments if the comment delimiters aren't at the beginning and end of the line (excluding whitespace) or detect the single line comment style. &amp;nbsp;This may or may not be a problem depending on the coding style of the files you're trying to import, and ChrisNZ's code could probably be modified without much difficulty to take in most of the edge cases, but personally I think solving this a different way would be preferable. &amp;nbsp;Just my $0.02.&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 00:18:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359525#M274533</guid>
      <dc:creator>Sven111</dc:creator>
      <dc:date>2017-05-18T00:18:08Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359576#M274534</link>
      <description>&lt;P&gt;The simplest method - and bearing in mind you need to evaluate multiple assignments and such like for instance in one file abc might be c:\dir1, in another program it might be c:\dir2, so an automatic approach might not work - would be to take a copy of SASHELP.VLIBNAME, run the programs i.e. %include, then just take a list of SASHELP.VLIBNAME not in your copy:&lt;/P&gt;
&lt;P&gt;E.g:&lt;/P&gt;
&lt;PRE&gt;data temp;
  set sashelp.vlibnam;
run;

libname abc "s:\temp\rob";

proc sql;
  create table WANT as
  select * from SASHELP.VLIBNAM 
  except select * from TEMP;
quit; 

libname abc clear;&lt;/PRE&gt;
&lt;P&gt;This will create want with one row for the libname I just created with name and path. &amp;nbsp;Far simpler than re-implementing a text parser to &amp;nbsp;work out what is what - note it wont pick up on duplicates however!&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 09:06:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/359576#M274534</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-05-18T09:06:05Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360006#M274535</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; that was really good code that helped me out thanks for the help.&lt;BR /&gt;Have a question for you&lt;BR /&gt;What if i have situation where i have a dlm=";" option set while reading the inputs.How can i solve that situation.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Fri, 19 May 2017 14:59:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360006#M274535</guid>
      <dc:creator>User12</dc:creator>
      <dc:date>2017-05-19T14:59:30Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360337#M274536</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;dlm=';'
&lt;/PRE&gt;
&lt;P&gt;makes no difference.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  input STATEMENT $80.;
  file "%sysfunc(pathname(work))\t.txt";
  put STATEMENT; 
cards4;
Libname sample1 "XYZ";
Libname sample2 "ABC";
/*Libname sample3 "asdfghjj";*/
Libname sample4 "uxcvdgh";
/*commented out
Libname sample5 "XYZasdf";
Libname sample6 "XYZasdfgb";**/
Libname sample7 "XYZdefrgevsdc";
;;;;
run;

data WANT;
  infile "%sysfunc(pathname(work))\t.txt" pad dlm=';';
  input STATEMENT $80.;
  if STATEMENT =:'/*' then COMMENT+1;
  if not COMMENT then output;
  if reverse(trim(STATEMENT))  =:'/*' then COMMENT=0;
  keep STATEMENT;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;NOTE: The data set WORK.WANT has 4 observations and 1 variables.&lt;/P&gt;</description>
      <pubDate>Sun, 21 May 2017 22:50:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360337#M274536</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-05-21T22:50:15Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360433#M274537</link>
      <description>Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; i am using dlm while reading the data i.e., in data _null_ in this case.&lt;BR /&gt;&lt;BR /&gt;Thanks</description>
      <pubDate>Mon, 22 May 2017 13:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360433#M274537</guid>
      <dc:creator>User12</dc:creator>
      <dc:date>2017-05-22T13:48:01Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360583#M274538</link>
      <description>&lt;P&gt;I don't understand.&lt;/P&gt;</description>
      <pubDate>Mon, 22 May 2017 23:19:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360583#M274538</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-05-22T23:19:07Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360738#M274539</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt; i have a delimiter set while reading the libname statements into a dataset.&lt;/P&gt;&lt;P&gt;i.e., &amp;nbsp;the dlm is set in first data step itself &lt;STRONG&gt;not in WANT Data step.&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;thanks&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 14:02:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360738#M274539</guid>
      <dc:creator>User12</dc:creator>
      <dc:date>2017-05-23T14:02:35Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360964#M274540</link>
      <description>&lt;P&gt;That's what I do in my second example, isn't it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I use&amp;nbsp; &lt;FONT face="courier new,courier"&gt;dlm=';'&lt;/FONT&gt;&amp;nbsp; to &lt;STRONG&gt;read&lt;/STRONG&gt; the data from an external file &lt;STRONG&gt;into&lt;/STRONG&gt; a data set.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 23:30:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/360964#M274540</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-05-23T23:30:07Z</dc:date>
    </item>
    <item>
      <title>Re: Removing Comments</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/363241#M274541</link>
      <description>To generate code without the  block-commented code, would this approach work?&lt;BR /&gt;Before the first line of the code add this statement:&lt;BR /&gt;%MACRO COMMENTREMOVAL ;&lt;BR /&gt;After all the statements,  add statements&lt;BR /&gt;%MEND  COMMENTREMOVAL ;&lt;BR /&gt;FILENAME MPRINT TEMP ;&lt;BR /&gt;OPTION MPRINT MFILE  LRECL= 3000 ;&lt;BR /&gt;%COMMENTREMOVAL ;&lt;BR /&gt;RUN ;&lt;BR /&gt;OPTION NOMFILE ;&lt;BR /&gt;DATA _NULL_ ;&lt;BR /&gt;INFILE MPRINT ;&lt;BR /&gt;INPUT ;&lt;BR /&gt;LIST ;&lt;BR /&gt;RUN ;&lt;BR /&gt; I think this should echo to the log, a file of the code generated. It will not include the block-commented code. It has the downside that the code would need to be  executed to generate this file of "clean" code.</description>
      <pubDate>Wed, 31 May 2017 21:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-Comments/m-p/363241#M274541</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2017-05-31T21:51:28Z</dc:date>
    </item>
  </channel>
</rss>

