<?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: Extracting sas code from sas log in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/790724#M266735</link>
    <description>&lt;P&gt;To get rid of line numbers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Open the log.&lt;/P&gt;&lt;P&gt;Export as a RTF&lt;/P&gt;&lt;P&gt;Open in Word&lt;/P&gt;&lt;P&gt;Copy All&lt;/P&gt;&lt;P&gt;Paste into Excel&lt;/P&gt;&lt;P&gt;Use Text-to-Columns&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use Fixed Width&lt;/P&gt;&lt;P&gt;Position line break between line numbers and SAS Code&lt;/P&gt;&lt;P&gt;Voila!&lt;/P&gt;</description>
    <pubDate>Tue, 18 Jan 2022 17:34:41 GMT</pubDate>
    <dc:creator>PASASMAN</dc:creator>
    <dc:date>2022-01-18T17:34:41Z</dc:date>
    <item>
      <title>Extracting sas code from sas log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/199906#M266729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have a sas log and I want to extract from it a sas code&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 22:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/199906#M266729</guid>
      <dc:creator>LineMoon</dc:creator>
      <dc:date>2015-07-09T22:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sas code from sas log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/199907#M266730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you have just run a program in base SAS you can press the F4 key and code will be "recalled" into the program editor.&lt;/P&gt;&lt;P&gt;Otherwise you can highlight lines in the log and copy/paste into the editor, which will likely require some editing to remove notes.&lt;/P&gt;&lt;P&gt;Or save the log to a text file and edit with any editor.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 09 Jul 2015 22:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/199907#M266730</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2015-07-09T22:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sas code from sas log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/199908#M266731</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want to extract the SAS Code in a log file and store it in a dataset then the below code will help you&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;In logs the SAS code will be preceded with line numbers. So first pick the lines which are starting with numbers. Here I stored the data in the variable Code1.&lt;/P&gt;&lt;P&gt;If you need only the SAS Code with out the line numbers then use substr to extract only the code leaving the line numbers. Here I stored the same in the variable Code.&lt;/P&gt;&lt;P&gt;There will be blank lines in the code and the blank spaces will be stored in the dataset as observations.We can exclude these observations by using the if condition.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data SASCode;&lt;/P&gt;&lt;P&gt;infile "path\logfilename.txt";&lt;/P&gt;&lt;P&gt;input dat $1000.;&lt;/P&gt;&lt;P&gt;dat = _infile_;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if substr(left(_infile_),1,1) in ('1','2','3','4','5','6','7','8','9','0') then code1 = _infile_;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;code = substr(code1,index(code1," "));&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;keep code;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;if code ne " ";&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you want to export the code into any flat file then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc export data = SASCode outfile = "xxx" &lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;dbms= xxx&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;replace;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jul 2015 08:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/199908#M266731</guid>
      <dc:creator>MadhuKorni</dc:creator>
      <dc:date>2015-07-10T08:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sas code from sas log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/599009#M266732</link>
      <description>&lt;P&gt;If you're looking at a workspace server log, each line may be preceded by a date/time stamp, log level info and a username. Assuming a linux environment, you can use the following command line syntax.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;Be sure to set the correct log file name and also replace the username (john_doe) in 2 places in the statement.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This will generate a file in the same location as the log, with the same name as the log, with a ".sas.recover" extension. Note that this recovered code should be used with caution, and only as reference, because parts might not be included, macros may be expanded, etc based on options that are set.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;logname=&lt;STRONG&gt;SASApp_WorkspaceServer_2019-10-07_hostA_342040.log&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;FONT color="#0000FF"&gt;grep "&lt;STRONG&gt;john_doe&lt;/STRONG&gt; \- [0-9]" ${logname} | grep -v 'The SAS System' |awk -F'&lt;STRONG&gt;john_doe&lt;/STRONG&gt; - ' '{print $2}'| sed -E 's/([0-9]+) //' &amp;gt; `dirname ${logname}`/`basename ${logname} .log`.sas.recover&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;This is written for Workspace server logs specifically. To run this on Batch or Connect logs, adjust the regex in the grep statement accordingly. The sed statement can remain as is.&lt;/DIV&gt;</description>
      <pubDate>Thu, 24 Oct 2019 12:45:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/599009#M266732</guid>
      <dc:creator>helge-h</dc:creator>
      <dc:date>2019-10-24T12:45:54Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sas code from sas log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/599319#M266733</link>
      <description>&lt;P&gt;What is the real life scenario here, why can't you get the code the regular way? Is it lost?&lt;/P&gt;
&lt;P&gt;If the code is very extensive, you should have saved it.&lt;/P&gt;
&lt;P&gt;If it's simple code, you can probably recreate it.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 13:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/599319#M266733</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2019-10-25T13:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sas code from sas log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/599322#M266734</link>
      <description>&lt;P&gt;The real life scenario is: The code is very extensive. An earlier version was saved but significant changes were lost. Deadlines don't allow for recreation of the lost changes and this method to extract the code from the log facilitated meeting the deadline.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2019 13:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/599322#M266734</guid>
      <dc:creator>helge-h</dc:creator>
      <dc:date>2019-10-25T13:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sas code from sas log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/790724#M266735</link>
      <description>&lt;P&gt;To get rid of line numbers:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Open the log.&lt;/P&gt;&lt;P&gt;Export as a RTF&lt;/P&gt;&lt;P&gt;Open in Word&lt;/P&gt;&lt;P&gt;Copy All&lt;/P&gt;&lt;P&gt;Paste into Excel&lt;/P&gt;&lt;P&gt;Use Text-to-Columns&amp;nbsp;&lt;/P&gt;&lt;P&gt;Use Fixed Width&lt;/P&gt;&lt;P&gt;Position line break between line numbers and SAS Code&lt;/P&gt;&lt;P&gt;Voila!&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 17:34:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/790724#M266735</guid>
      <dc:creator>PASASMAN</dc:creator>
      <dc:date>2022-01-18T17:34:41Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sas code from sas log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/790725#M266736</link>
      <description>Real life scenario is I don't want to write 100 lines of data input. When usintg the Import Wizard, SAS generates the code along with formats and informats.</description>
      <pubDate>Tue, 18 Jan 2022 17:35:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/790725#M266736</guid>
      <dc:creator>PASASMAN</dc:creator>
      <dc:date>2022-01-18T17:35:34Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting sas code from sas log</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/790798#M266737</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/413169"&gt;@PASASMAN&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Real life scenario is I don't want to write 100 lines of data input. When usintg the Import Wizard, SAS generates the code along with formats and informats.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you are using PROC IMPORT to GUESS how to read a delimited file you can also use some other method to perform the guessing and code generation.&amp;nbsp; Then it will be easier to have the generated code and/or metadata.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try running this macro on your file(s).&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/csv2ds.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/csv2ds.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;It will leave you with both a text file with the code and a dataset with the metadata.&lt;/P&gt;
&lt;P&gt;Plus it will run faster and allow you to override the guessed metadata.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Jan 2022 03:30:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extracting-sas-code-from-sas-log/m-p/790798#M266737</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-19T03:30:51Z</dc:date>
    </item>
  </channel>
</rss>

