<?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: code improvement to run fast in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652287#M195803</link>
    <description>&lt;P&gt;Sorting is one of the most common and time intensive activities.&lt;/P&gt;
&lt;P&gt;Are you using indexed data sets? Using indexes instead of sorts can speed some activities. Are you rebuilding the same data every day? Appending to existing data?&lt;/P&gt;
&lt;P&gt;Does the data reside in an external DBMS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What exactly are you doing that requires multiple sorts? Can you provide specific examples of the code using the different sorts?&lt;/P&gt;
&lt;P&gt;Sometimes a careful sort order selection can allow reuse of the same data without resorting. And if you are doing multiple summaries of data then perhaps use of class variables in a procedure like Proc Summary could do multiple summaries and select the needed one by using a selection of the created _type_ variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some details may help.&lt;/P&gt;</description>
    <pubDate>Mon, 01 Jun 2020 20:35:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2020-06-01T20:35:46Z</dc:date>
    <item>
      <title>code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652285#M195802</link>
      <description>&lt;P&gt;Hi team,&lt;/P&gt;&lt;P&gt;Currently i am having a code which starts at&amp;nbsp;02:49:17 and ends at 07:04:57 time.because of this the sas dataset is over running and users are trying to access the datasets from their end which is causing failure and chances datasets will not be updated with correct data.&lt;/P&gt;&lt;P&gt;i can not change the schedule as it is dependent on other datasets also.&lt;/P&gt;&lt;P&gt;so i thought of&amp;nbsp; trying to improve the performance of the code so that it will be running fast.this is just my thought.&lt;/P&gt;&lt;P&gt;i am having a very low knowledge so i am requesting to please provide your thoughts as i believe that will be more excellent and efficinet options please.&lt;/P&gt;&lt;P&gt;iam having so many proc sorts in code- please suggest can i do something on this example : tagsort option or any other advice please&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 15:34:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652285#M195802</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-01T15:34:22Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652287#M195803</link>
      <description>&lt;P&gt;Sorting is one of the most common and time intensive activities.&lt;/P&gt;
&lt;P&gt;Are you using indexed data sets? Using indexes instead of sorts can speed some activities. Are you rebuilding the same data every day? Appending to existing data?&lt;/P&gt;
&lt;P&gt;Does the data reside in an external DBMS?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What exactly are you doing that requires multiple sorts? Can you provide specific examples of the code using the different sorts?&lt;/P&gt;
&lt;P&gt;Sometimes a careful sort order selection can allow reuse of the same data without resorting. And if you are doing multiple summaries of data then perhaps use of class variables in a procedure like Proc Summary could do multiple summaries and select the needed one by using a selection of the created _type_ variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Some details may help.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 20:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652287#M195803</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-01T20:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652288#M195804</link>
      <description>&lt;P&gt;Given what you've posted, my suggestion would be to search "efficient coding strategies"&amp;nbsp; or "make code faster" on lexjansen.com and read through the paper there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A class="gs-title" dir="ltr" href="https://www.google.com/url?client=internal-element-cse&amp;amp;cx=011240857950991443104:hsqcj3nokh0&amp;amp;q=http://support.sas.com/resources/papers/proceedings12/257-2012.pdf&amp;amp;sa=U&amp;amp;ved=2ahUKEwiS8bzi_-DpAhVRFjQIHaQPClYQFjAAegQIARAB&amp;amp;usg=AOvVaw3RyhkTab5UrlRuh5er_pav" target="_blank" rel="noopener" data-cturl="https://www.google.com/url?client=internal-element-cse&amp;amp;cx=011240857950991443104:hsqcj3nokh0&amp;amp;q=http://support.sas.com/resources/papers/proceedings12/257-2012.pdf&amp;amp;sa=U&amp;amp;ved=2ahUKEwiS8bzi_-DpAhVRFjQIHaQPClYQFjAAegQIARAB&amp;amp;usg=AOvVaw3RyhkTab5UrlRuh5er_pav" data-ctorig="http://support.sas.com/resources/papers/proceedings12/257-2012.pdf"&gt;50 Ways to&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Make&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Your SAS®&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Code&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Execute More Efficiently&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.google.com/url?client=internal-element-cse&amp;amp;cx=011240857950991443104:hsqcj3nokh0&amp;amp;q=http://support.sas.com/resources/papers/proceedings12/257-2012.pdf&amp;amp;sa=U&amp;amp;ved=2ahUKEwiS8bzi_-DpAhVRFjQIHaQPClYQFjAAegQIARAB&amp;amp;usg=AOvVaw3RyhkTab5UrlRuh5er_pav" target="_blank"&gt;https://www.google.com/url?client=internal-element-cse&amp;amp;cx=011240857950991443104:hsqcj3nokh0&amp;amp;q=http://support.sas.com/resources/papers/proceedings12/257-2012.pdf&amp;amp;sa=U&amp;amp;ved=2ahUKEwiS8bzi_-DpAhVRFjQIHaQPClYQFjAAegQIARAB&amp;amp;usg=AOvVaw3RyhkTab5UrlRuh5er_pav&amp;nbsp;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Twenty Ways to Run Your SAS® Program Faster and Use Less&lt;BR /&gt;Space&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3684-2019.pdf" target="_blank"&gt;https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2019/3684-2019.pdf&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 16:09:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652288#M195804</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-01T16:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652292#M195806</link>
      <description>&lt;P&gt;Thanks, i will check and try.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;May i know is there any other approach you can see and suggest as i am from basic level of knowledge on this issue please&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 16:33:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652292#M195806</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-01T16:33:30Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652294#M195807</link>
      <description>&lt;P&gt;As BallardW indicates you need to provide more details. Vague questions get vague answers.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 16:41:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652294#M195807</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-01T16:41:13Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652301#M195810</link>
      <description>Look into hashing.  The most common reason that sorts are done in SAS is to merge in following steps.   If you use hashing, then you dont need to sort either table.   Hashing is really useful when working with huge tables and you need to look up things in other "smaller" tables.   The proviso is that the smaller table need to comfortably fit in memory.   In an optimization consulting project where a table of 100 million records was had to be summarised after being enriched from multiple other sources, I managed to avoid all sorts and the large table  was only parsed.  The final output was a table with only 20,000 records and maybe 20 columns.    The summary was done into a hash table and all enrichment was done in the same step.   It was possible to reduce a run time of 1 hour into 1 minute. &lt;BR /&gt;But this may not fit your problem:  indeed, maybe you could simply adjust the memsize and sortsize options to get a huge boost in performance, without changing any code.</description>
      <pubDate>Mon, 01 Jun 2020 17:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652301#M195810</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-06-01T17:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652302#M195811</link>
      <description>ok but code is very large. but the code is written in a efficient way only as i just checked and compared the code with the documnet on "Twenty Ways to Run Your SAS® Program Faster and Use Less&lt;BR /&gt;Space"</description>
      <pubDate>Mon, 01 Jun 2020 17:07:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652302#M195811</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-01T17:07:10Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652310#M195813</link>
      <description>&lt;P&gt;To make suggestions on possible improvements for your code, we need to see it. Since the log contains performance-relevant information, we need to see it too.&lt;/P&gt;
&lt;P&gt;If you can identify single steps that take up most of the time, these need to be worked on first.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Undertaking a large job for production use with large data while having only basic knowledge is, of course, the wrong way to go. You build your skills with small tasks first, then apply the experience you gained to the bigger issues later.&lt;/P&gt;
&lt;P&gt;If time is of the essence, I suggest you hire a consultant and then learn from the methods used by said consultant. I had some of my important early "aha" moments like this.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 18:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652310#M195813</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-01T18:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652316#M195816</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;below code is taking more time(24:39.42) compared with the rest of all code and other sections of code is of seconds only maximum 7 minutes. would you please suggest any option to improve the below code&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data 2a (drop=ty amt);
set ay;
by num no no1;
if ty      = 'AA' then ccb  = amt;
else if ty = 'BB'  then cles = amt;
else if ty = 'CCC' then nut  = amt;
else if ty = 'DDD' then amp   = amt;
else if ty = 'EE' then ss = amt;
else if ty = 'FFF' then rat = amt;
else if ty = 'GGG' then xcv  = amt;
else if ty = 'HHH' then wee    = amt;
else if ty = 'II' then ler  = amt;
else if ty = 'JJJ' then mit  = amt;
else if ty = 'KK' and hhhoi in ('SETL' 'SET1' 'SET2' 'SET3') then do;
if gjhrt = '16' then ghfcv = 'SD';
else ghfcv = 'ED';
end;
 
retain ccb amp cles nut ler mit
ss rat xcv wee 0 ghfcv " ";
 
if last.no1 then do;
output;
ccb  = 0;
cles = 0;
nut  = 0;
amp   = 0;
ss = 0;
rat = 0;
xcv  = 0;
wee    = 0;
ler  = 0;
mit  = 0;
ghfcv    = " ";
end;
run;
 
proc datasets lib=work memtype=data;
delete ay;
run;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jun 2020 17:54:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652316#M195816</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-01T17:54:16Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652329#M195819</link>
      <description>&lt;P&gt;Looks sort of like a transpose.&amp;nbsp; Perhaps you don't need to do the transpose at all?&lt;/P&gt;
&lt;P&gt;How do you use the dataset, 2A?&amp;nbsp;&lt;SPAN style="font-family: inherit;"&gt;Is it used just once or multiple times?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 18:31:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652329#M195819</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-01T18:31:27Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652339#M195823</link>
      <description>How many records are in the input table, and how many are in the output table?   Showing the log of this excerpt, plus that of the previous proc sort of AY would help a lot.</description>
      <pubDate>Mon, 01 Jun 2020 18:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652339#M195823</guid>
      <dc:creator>DavePrinsloo</dc:creator>
      <dc:date>2020-06-01T18:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652341#M195824</link>
      <description>&lt;P&gt;When wetware is insufficient sometimes it is more cost effective and timely to improve the hardware.&amp;nbsp; More RAM, More SSD, More CPU, More Ghz&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 19:03:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652341#M195824</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-06-01T19:03:29Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652366#M195836</link>
      <description>&lt;P&gt;Which value of TY is the most common?&lt;/P&gt;
&lt;P&gt;If you have the more common values of the variable TY in that block of If/then/else then fewer ifs have to be evaluated.&lt;/P&gt;
&lt;P&gt;For example if the JJJ were the most common value then you have to execute 9 additional statements than if the block started with&lt;/P&gt;
&lt;P&gt;If ty = 'JJJ' then ...&lt;/P&gt;</description>
      <pubDate>Mon, 01 Jun 2020 20:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652366#M195836</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-01T20:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652391#M195846</link>
      <description>&lt;P&gt;I am guessing you tweaked the code somewhat because WORK.2A is not a valid data set name as coded, even with OPTIONS VALIDVARNAME=ANY.&lt;/P&gt;
&lt;P&gt;Things to check are excessively long variables such as $4096 when $20 is sufficient.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output data set uses option (DROP=) and could allow un-needed 'tag-along' variables in your per-group data record, an explicit (KEEP=) could be helpful.&lt;/P&gt;
&lt;P&gt;As for&lt;/P&gt;
&lt;PRE class="language-sas"&gt;&lt;CODE&gt;by num no no1;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;How many by groups do you have ?&lt;/P&gt;
&lt;P&gt;Is data set AY constructed elsewhere with a JOIN ?&amp;nbsp; If so, the real world data might be subverting the expectations of the join criteria.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have any log snippets that showing the steps&lt;/P&gt;
&lt;P&gt;- number of observations read and written&lt;/P&gt;
&lt;P&gt;- system memory and cpu&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Get more info by setting&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;OPTIONS FULLSTIMER;&lt;/PRE&gt;
&lt;P&gt;Log snippet should look like&lt;/P&gt;
&lt;PRE&gt;NOTE: There were #### observations read from the data set ********.********
NOTE: The data set ********.******** has #### observations and #### variables.
NOTE: DATA statement used (Total process time):
      real time           0.03 seconds
      user cpu time       0.00 seconds
      system cpu time     0.01 seconds
      memory              708.40k
      OS Memory           24584.00k
      Timestamp           06/01/2020 06:56:30 PM
      Step Count                        401  Switch Count  0
&lt;/PRE&gt;
&lt;P&gt;Can you show the output from&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc CONTENTS data=&amp;lt;name of SET data set&amp;gt;&lt;BR /&gt;Proc CONTENTS data=&amp;lt;name of OUTPUT data set&amp;gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Jun 2020 23:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652391#M195846</guid>
      <dc:creator>RichardDeVen</dc:creator>
      <dc:date>2020-06-01T23:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652414#M195860</link>
      <description>&lt;P&gt;After you create dataset 2A (an erroneous data set name), you delete data set AY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I presume AY is created earlier in the program, i.e. it's not a permanent data set.&amp;nbsp; If so, then you might save some resources by declaring AY as a data set VIEW rather than a data set FILE&amp;nbsp; (i.e. &amp;nbsp; DATA AY/ view=AY;&amp;nbsp; instead of DATA AY;).. &amp;nbsp; This can speed things up, because AY is never written to disk.&amp;nbsp; Instead its contents are dynamically generated and passed to the DATA 2A step only when the SET AY statement is encountered. &amp;nbsp;&amp;nbsp; If AY is not used multiple times in your program, this will likely save a lot of resources and time ordinarily needed to write data to disk only to re-read and discard it.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 02:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652414#M195860</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-06-02T02:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652416#M195862</link>
      <description>&lt;P&gt;My suspicion is that disk or network I/O is the bottleneck. If this data step runs for 24+ minutes AND source ay is a table and not a view then it must be high volume - really a lot of rows and variables and/or some character variables with a big length.&lt;/P&gt;
&lt;P&gt;- Turn on option FULLSTIMER and share the log with us.&lt;/P&gt;
&lt;P&gt;- Run a Proc Contents on ay and share the result with us.&lt;/P&gt;
&lt;P&gt;- Drop all variables you can from input data set ay - in the set statement something like: set ay(keep=....);&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Set option COMPRESS=YES at the start of your program and test if this improves runtimes&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below some tweaks to the code you've posted. Not sure if this will improve execution time.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _2a (drop=ty amt _ind);
  set ay;
  by num no no1;

  array a_vars {*} ccb cles nut amp ss rat xcv wee ler mit;
  _ind=WHICHC(ty, 'AA','BB','CCC','DDD','EE','FFF','GGG','HHH','II','JJJ');
  if _ind&amp;gt;0 then a_vars(_ind)=amt;
  else if ty = 'KK' and hhhoi in ('SETL' 'SET1' 'SET2' 'SET3') then
    do;
      if gjhrt = '16' then ghfcv = 'SD';
      else ghfcv = 'ED';
    end;

  retain ccb amp cles nut ler mit ss rat xcv wee 0 ghfcv " ";
  if last.no1 then
    do;
      output;
      ccb  = 0;
      cles = 0;
      nut  = 0;
      amp   = 0;
      ss = 0;
      rat = 0;
      xcv  = 0;
      wee    = 0;
      ler  = 0;
      mit  = 0;
      ghfcv    = " ";
    end;
run;

proc datasets lib=work memtype=data nolist;
  delete ay;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 03:22:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652416#M195862</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-02T03:22:15Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652417#M195863</link>
      <description>&lt;P&gt;1. All the comments made before are entirely valid.&lt;/P&gt;
&lt;P&gt;The most valid one is: show us more.&lt;/P&gt;
&lt;P&gt;If you call a garage and state that your car runs poorly and don't give more details, the chances of a useful diagnostic are zero.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. You are showing 2 steps here. How long do they take?&lt;BR /&gt;To repeat the message you seem to stubbornly ignore: where's the log?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. This code hardly does anything. Show us the log please. It looks like you must have slow disks if this simple logic takes time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. If you have slow disks, large (and small) tables are best stored in SPDE format with binary compression turned on. This lowers disk access, and also allows on-the-fly sorting, which is rather efficient. &lt;BR /&gt;Since you mention sorting as an issue (but then you show us a data step as an example of a slow step for some reason) this could be a double-win.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. If you have data steps doing so little processing, it is possible (and common) that the code multiplies time-consuming baby steps instead of having fewer smarter steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;6. How long does the &lt;FONT face="courier new,courier"&gt;proc datasets&lt;/FONT&gt; take? If you have slow libraries (read RDBMS, or very sadly SPDE), this deletion could take a while for no good reason. Replace the&amp;nbsp;&lt;FONT face="courier new,courier"&gt;proc datasets&lt;/FONT&gt;&amp;nbsp;step with:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;proc delete data=AY; run;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 06:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652417#M195863</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-02T06:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652435#M195875</link>
      <description>&lt;P&gt;HI&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;Previously i thought&amp;nbsp; proc sort with out really seeing the full code.&lt;/P&gt;&lt;P&gt;and then i followed as&amp;nbsp;@kurt suggested and found that the pasted data step taking more time compared with others sections of code please. thanks for the practical advise which i can easily understand&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;log part has PII info. how can i share please. how can i mask. the logs is very big please adivse&lt;/P&gt;&lt;P&gt;NO RDMS pure SAS tables.&lt;/P&gt;&lt;P&gt;Actualy i can share whole code but this has PII info.to mask i think manually it will take more time. please suggest if you have any options for me so that i can share log along with the code and to get the best help from you please&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 08:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652435#M195875</guid>
      <dc:creator>JJP1</dc:creator>
      <dc:date>2020-06-02T08:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652510#M195909</link>
      <description>&lt;P&gt;As ChrisNZ said, try option and spde engine(which have some drawback ) .&lt;BR /&gt;&lt;BR /&gt;1)&lt;BR /&gt;options bufno=100 bufsize=128k compress=yes&amp;nbsp;threads cpucount=4 ;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;2)&lt;BR /&gt;libname x spde 'c:\temp';&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 11:53:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652510#M195909</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-06-02T11:53:14Z</dc:date>
    </item>
    <item>
      <title>Re: code improvement to run fast</title>
      <link>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652517#M195914</link>
      <description>&lt;P&gt;If your data step throws lots of messages to the log, this can be part of the problem. If that is the case, sanitize your data steps(s) so that only the essential NOTEs are displayed:&lt;/P&gt;
&lt;PRE&gt; NOTE: There were 19 observations read from the data set SASHELP.CLASS.
 NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
 NOTE:  Verwendet wurde: DATA statement - (Gesamtverarbeitungszeit):
       real time           0.00 seconds
       cpu time            0.00 seconds&lt;/PRE&gt;
&lt;P&gt;A data step that comes back with more than these needs to be fixed. No "invalid data", "numeric converted to character", "character converted to numeric", "missing values because of ..." allowed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If in doubt, show us the summary lines of your long-running data step; these should not contain critical information (you may want to mask the dataset names).&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jun 2020 11:57:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/code-improvement-to-run-fast/m-p/652517#M195914</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-06-02T11:57:16Z</dc:date>
    </item>
  </channel>
</rss>

