<?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: Pick Only SQL part from SAS code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/614382#M179575</link>
    <description>Got it!! . Thanks !!</description>
    <pubDate>Mon, 30 Dec 2019 12:50:38 GMT</pubDate>
    <dc:creator>arunrami</dc:creator>
    <dc:date>2019-12-30T12:50:38Z</dc:date>
    <item>
      <title>Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613043#M178993</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am doing some mass code update task, for that will have to find only the proc sql step from all the sas code in certain path ,&amp;nbsp;&lt;/P&gt;&lt;P&gt;it has been very boring and time taking process of manually going in to all the code ans search "proc sql" ..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;though I am using sas code to find all the code with "proc sql" keyword, it is picking only that particular line , not the whole sql script under "proc sql".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just wondering , is there any simplest way I can take proc sql step from sas code, either by using file handling program or sas EG ?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-SAR&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 14:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613043#M178993</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2019-12-19T14:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613049#M178996</link>
      <description>&lt;P&gt;Yes, one way do that would be using regular expressions.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It could be tricky if you have constructs that dynamically generate SQL code on run time. You might have to check the results by hand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you upload a test file for me to work with please?&lt;/P&gt;&lt;P&gt;Are you in a windows environment?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 14:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613049#M178996</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2019-12-19T14:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613051#M178998</link>
      <description>&lt;P&gt;&lt;EM&gt;"though I am using sas code to find all the code with "proc sql" keyword,"&lt;/EM&gt; - Sounds like you wrote a very smart and a great code. I wish I could write like that. Can you please share the code if you don't mind. I would like to use that too.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/200330"&gt;@arunrami&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am doing some mass code update task, for that will have to find only the proc sql step from all the sas code in certain path ,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;it has been very boring and time taking process of manually going in to all the code ans search "proc sql" ..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;though I am using sas code to find all the code with "proc sql" keyword, it is picking only that particular line , not the whole sql script under "proc sql".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just wondering , is there any simplest way I can take proc sql step from sas code, either by using file handling program or sas EG ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;-SAR&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 14:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613051#M178998</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-12-19T14:25:08Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613058#M178999</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With vim, you can open a fiile in the given path and issue the command :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;:vim "proc sql" *.sas&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It will search for the string "proc sql" in all sas files in the same directory.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can access the list of results with the command&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;:cw&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It opens a new buffer with the list of results (file names, line numbers, code extract). If you move the cursor on&lt;/P&gt;
&lt;P&gt;a given line and hit enter, it will open the corresponding file at the appropriate line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use "&amp;lt;CTRL-w&amp;gt; w" to switch between results buffer and sas code.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 14:30:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613058#M178999</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-12-19T14:30:38Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613062#M179001</link>
      <description>&lt;P&gt;Just as you are using a program to locate all instances of "proc sql" you could use the same program to locate "quit;" which marks the end of the SQL step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are complications.&amp;nbsp; Some programmers don't bother to add the QUIT statement.&amp;nbsp; Sometimes macro language generates part or all of the SQL code, so you don't actually see "proc sql" in the program itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sometimes, SQL code and macro code get intertwined.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;a SELECT statement extracts data into a macro variable.&lt;/LI&gt;
&lt;LI&gt;a %LET statement utilizes the value of that macro variable.&lt;/LI&gt;
&lt;LI&gt;another SELECT statement executes&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;All of this can happen within a single PROC SQL.&amp;nbsp; So you have to decide if you want to extract the macro code along with the SQL statements.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The bottom line:&amp;nbsp; search for "quit;" can help shorten the task, but probably won't get you 100% of the results that you need.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 14:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613062#M179001</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-12-19T14:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613069#M179004</link>
      <description>&lt;P&gt;Inspired by&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&amp;nbsp;post -&amp;nbsp;&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Searching-SAS-code-for-keywords/m-p/390379/highlight/true#M93625" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/Searching-SAS-code-for-keywords/m-p/390379/highlight/true#M93625&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 16:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613069#M179004</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2019-12-19T16:53:56Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613112#M179020</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/200330"&gt;@arunrami&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As others pointed out, there can be many problems, but the following code will de the rough work. It extracts all sql steps beginning with&amp;nbsp; a line starting with &lt;EM&gt;proc sql&lt;/EM&gt;&amp;nbsp;and ending with a new line starting with &lt;EM&gt;quit&lt;/EM&gt;&amp;nbsp;, or until a new line starts with &lt;EM&gt;proc&lt;/EM&gt;, &lt;EM&gt;data&lt;/EM&gt; or &lt;EM&gt;run&lt;/EM&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Arguments to the macro is&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;the name of a data set with a list of all programs (full path), and&lt;/LI&gt;
&lt;LI&gt;the name of the variable containing the path.&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro scanfiles(filelist,filevar);
	proc datasets lib=work nolist nodetails nowarn;
		delete jobsfound;
	quit;

	%let pgmcnt = 0;
	proc sql noprint;
		select count(*) into :pgmcnt
		from &amp;amp;filelist;
	quit;
	%put &amp;amp;=pgmcnt;

	%do i = 1 %to 200; *&amp;amp;pgmcnt;
		data _null_;
			set &amp;amp;filelist(obs=&amp;amp;i firstObs=&amp;amp;i);
			call symput("filsti",&amp;amp;filevar);
		run;

		filename saspgm "&amp;amp;filsti";
		data d (drop=instep sqlfound startrec);
			length filsti $255;
			infile SASpgm truncover lrecl = 255 end=eop;
			retain StepNo 0 instep 0 sqlfound 0 startrec;
			Filsti = "&amp;amp;filsti";

			input @1 s $char255.;
			s = tranwrd(s,'09'x,'    ');
			recno = _N_;

			if lowcase(s) =: 'proc sql' then do;
				startrec = recno;
				sqlfound = 1;
				instep = 1;
				StepNo = StepNo + 1;
			end;
			if recno &amp;gt; startrec and lowcase(scan(s,1,'; ')) in ('proc','data','run') then instep = 0;
			if instep = 1 and s ne '' then output;
			if lowcase(scan(s,1,'; ')) = 'quit' then instep = 0;
			if eop then call symputx('sqlfound',sqlfound);
		run;
		filename saspgm clear;
		%put &amp;amp;=filsti &amp;amp;=sqlfound;

		%if &amp;amp;sqlfound &amp;gt; 0 %then %do;
			proc append base=jobsfound data=d; 
			run;
		%end;
	%end;
%mend;
%scanfiles(jobliste2,filsti);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Dec 2019 17:40:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613112#M179020</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-12-19T17:40:06Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613137#M179031</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;&amp;nbsp; .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 19:50:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613137#M179031</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2019-12-19T19:50:17Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613188#M179056</link>
      <description>&lt;P&gt;In Notepad++ you can search and mark with regular expression:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql\b.+?\bquit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;to highlight every SQL code block in SAS code. Check option ". matches newline" in search dialog.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Dec 2019 04:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613188#M179056</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-12-20T04:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613867#M179355</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12887"&gt;@ErikLund_Jensen&lt;/a&gt;&amp;nbsp; , just now gone through the code , it is really inspiring and of course it works like a charm&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't understand why you are using tranwrd here ..can you please elaborate bit more&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;FONT&gt;input @1 s $char255.;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;s = tranwrd(s,'09'x,'&amp;nbsp;&amp;nbsp;&amp;nbsp; ');&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;recno = _N_;&lt;/FONT&gt;s = tranwrd(s,'09'x,'    ');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks you again!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Dec 2019 09:36:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/613867#M179355</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2019-12-26T09:36:02Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/614373#M179573</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/200330"&gt;@arunrami&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The tranwrd function is not necessary. It changes a tab char ('09'x) to 4 spaces, and the sole purpose is to preserve indentation, so the code snippets look nice in the SAS data viewer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The programs I used to test the code are written using SAS Diaplay manager, where indentation of lines is made with tab characters, and each tab is shown as 4 spaces in the program editor. But the tab character has no meaning in the SAS data viewer, they simply diapppear, so all lines in a proc sql statement block are left aligned.&amp;nbsp;I wanted the code snippets to be shown the same way as when the program is opened in Display Manger, so I translated the tabs to 4 spaces.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 Dec 2019 11:52:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/614373#M179573</guid>
      <dc:creator>ErikLund_Jensen</dc:creator>
      <dc:date>2019-12-30T11:52:27Z</dc:date>
    </item>
    <item>
      <title>Re: Pick Only SQL part from SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/614382#M179575</link>
      <description>Got it!! . Thanks !!</description>
      <pubDate>Mon, 30 Dec 2019 12:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Pick-Only-SQL-part-from-SAS-code/m-p/614382#M179575</guid>
      <dc:creator>arunrami</dc:creator>
      <dc:date>2019-12-30T12:50:38Z</dc:date>
    </item>
  </channel>
</rss>

