<?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: How to reduce the time taken in running the following code. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317544#M69546</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format your code, indent the sections and follow this guidelines for a start.&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi29/258-29.pdf" target="_self"&gt;Guidelines for Coding of SAS® Programs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings12/257-2012.pdf" target="_self"&gt;50 Ways to Make Your SAS® Code Execute More Efficiently&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings12/357-2012.pdf" target="_self"&gt;Top Ten SAS ® Performance Tuning Techniques&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check how big your datasets are, and try to use a memlib instead of work.&lt;/P&gt;&lt;P&gt;You need to reduce the I/O operations and the amount of data beeing moved around.&lt;/P&gt;&lt;P&gt;Use where instead of if.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then ask again, by attaching your log and the text files if you didn't save at least half the process time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Thu, 08 Dec 2016 10:30:59 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2016-12-08T10:30:59Z</dc:date>
    <item>
      <title>How to reduce the time taken in running the following code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317499#M69530</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hello Friends,&lt;/P&gt;
&lt;P&gt;I am running the code written below and it takes almost 16 Hrs to finish the processing. I need your help in optimizing it in order to reduce the processing time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The time taken is mostly beacuse it sorts the dataset many times and everytime it reads and writes the dataset on to the machine hard disk.&lt;/P&gt;
&lt;P&gt;I Tried Tagsort option but it didn't reduce the time.&lt;/P&gt;
&lt;P&gt;I am unable to attach both the dataset here as it gives option of attaching a single file hence sharing a cloud link for the &lt;A title="SAS Dataset" href="https://1drv.ms/f/s!AmgOKgExCpSglDb7WLBJUc4afstl" target="_blank"&gt;Data-Set&lt;/A&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://1drv.ms/f/s!AmgOKgExCpSglDb7WLBJUc4afstl" target="_blank"&gt;https://1drv.ms/f/s!AmgOKgExCpSglDb7WLBJUc4afstl&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plz. Help me in optimizing the run time.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc printto log= 'G:\Test\l.txt'/*'C:\Users\RKD\Desktop\AT_Analysis\l.txt'*/ new ; 
run;
proc printto print='G:\Test\o.txt'/*'C:\Users\RKD\Desktop\AT_Analysis\o.txt'*/ new;
run;

data list; 
input names $ 20.;
if index(names,'&amp;amp;') then names=tranwrd(names,'&amp;amp;','and');
if index(names,'-') then names=tranwrd(names,'-','d');
if index(names,'3') then names=tranwrd(names,'3','t'); 
datalines; 
POWERGRID
;

proc sql noprint; 
select count(*) into :cnt from list; 
select distinct(names) into: mlist separated by ':' from list; 
quit; 
%macro omatching; 
%do j=1 %to &amp;amp;cnt %by 1; 
%let compname=%sysfunc(scan(&amp;amp;mlist,&amp;amp;j,':'));
%if &amp;amp;compname=IdFLEX %then %let symbol=%str(I-FLEX);
%else %let symbol=&amp;amp;compname;
%put &amp;amp;compname;

data &amp;amp;compname._trades;
set mac.&amp;amp;compname.trades;
tno=trdnum;
bno=buyordnum;
sno=sellordnum;
format tradetime time8.;
*tt=tradetime-'09:15:00't;
tp=tradeprice;
tq=trdqty;
run;
data &amp;amp;compname._trades;
set &amp;amp;compname._trades;
tt=tradetime-'09:15:00't;
keep tt tp tq bno sno tno;
run;
data &amp;amp;compname._orders;
set mac.&amp;amp;compname.orders;
rename ordnum = orno;
rename oactivity=acttype;
rename otype=bors;
rename VolDisclosed=vd;
rename oqty = vo;
rename ordprice=lp;
rename MLOrdInd=mkt;
rename Otime=otm;
rename ordtime = time;
format time time8.;
if stploss='N';
run;
data &amp;amp;compname._b;
set &amp;amp;compname._orders;
if bors='B';
bt=time-'09:15:00't;
run;
data &amp;amp;compname._s;
set &amp;amp;compname._orders;
if bors='S';
st=time-'09:15:00't;
run;

data &amp;amp;compname._b;
set &amp;amp;compname._b;
bp=lp;
bq=vo;
bdq=vd;
bqo=vo;
btype=acttype;
borno=orno;
btime=time;
if time=. then delete;
keep borno btype bp bq bdq bqo btime bt ;
run;
data &amp;amp;compname._s;
set &amp;amp;compname._s;
if time=. then delete;
sp=lp;
sq=vo;
sdq=vd;
sqo=vo;
stype=acttype;
sorno=orno;
stime=time;
keep sorno stype sp sq sdq sqo stime st ;
run;
%do i=1 %to 22501 %by 60; 
%let tm=&amp;amp;i;
data &amp;amp;compname._bord&amp;amp;i;
set &amp;amp;compname._b;
if &amp;amp;tm-60 &amp;lt; bt &amp;lt;= &amp;amp;tm;
bno=borno;
run;
data &amp;amp;compname._sord&amp;amp;i;
set &amp;amp;compname._s;
if &amp;amp;tm-60 &amp;lt; st &amp;lt;= &amp;amp;tm;
sno=sorno;
run;
proc append base=&amp;amp;compname._bsnap data=&amp;amp;compname._bord&amp;amp;i force;
run;
proc append base=&amp;amp;compname._ssnap data=&amp;amp;compname._sord&amp;amp;i force;
run;
data _null_; 
if 0 then set &amp;amp;compname._bord&amp;amp;i nobs=num1; 
call symput('num1',put(num1,8.-l)); 
stop; 
run; 
data _null_; 
if 0 then set &amp;amp;compname._sord&amp;amp;i nobs=num2; 
call symput('num2',put(num2,8.-l)); 
stop; 
run; 
%macro borders;
proc sort data=&amp;amp;compname._bsnap TAGSORT;
by borno;
run;
data &amp;amp;compname._bsnap;
set &amp;amp;compname._bsnap;
by borno;
if last.borno;
run;
data &amp;amp;compname._bsnap;
set &amp;amp;compname._bsnap;
if btype=3 then delete;
run;
%mend borders;
%macro sorders;
proc sort data=&amp;amp;compname._ssnap TAGSORT;
by sorno;
run;
data &amp;amp;compname._ssnap;
set &amp;amp;compname._ssnap;
by sorno;
if last.sorno;
run;
data &amp;amp;compname._ssnap;
set &amp;amp;compname._ssnap;
if stype=3 then delete;
run;
%mend sorders;

%if &amp;amp;num1 &amp;gt; 0 %then %do; 
%borders;
%end; 
%if &amp;amp;num2 &amp;gt; 0 %then %do; 
%sorders;
%end;
data &amp;amp;compname._trades1;
set &amp;amp;compname._trades;
if &amp;amp;tm-60 &amp;lt; tt &amp;lt;= &amp;amp;tm;
run;
proc sort data=&amp;amp;compname._trades1 TAGSORT;
by bno;
run;
proc means data=&amp;amp;compname._trades1 sum;
var tq;
by bno;
output out=trab sum=stqb;
run;
data trab;
set trab;
drop _TYPE_ _FREQ_;
run;
proc sort data=trab TAGSORT;
by bno;
run;
proc sort data=&amp;amp;compname._trades1 TAGSORT;
by bno;
run;
proc sort data=&amp;amp;compname._bsnap TAGSORT;
by bno;
run;
data &amp;amp;compname._bsnap&amp;amp;i;
merge trab &amp;amp;compname._bsnap;
by bno;
run;
data &amp;amp;compname._bsnap&amp;amp;i;
set &amp;amp;compname._bsnap&amp;amp;i;
*if bno=borno then do;
if stqb=. then stqb=0;
bq=bq-stqb;
* end;
keep borno btype bp bq bdq bqo btime bt bno;
run;
data &amp;amp;compname._bsnap&amp;amp;i;
set &amp;amp;compname._bsnap&amp;amp;i;
if bq &amp;lt;= 0 then delete;
if bt=. then delete;
run;
proc sort data=&amp;amp;compname._bsnap&amp;amp;i TAGSORT;
by descending bp bt;
run;
data &amp;amp;compname._bsnap;
set &amp;amp;compname._bsnap&amp;amp;i;
run;
proc sort data=&amp;amp;compname._trades1 TAGSORT;
by sno;
run;
proc means data=&amp;amp;compname._trades1 sum;
var tq;
by sno;
output out=tras sum=stqs;
run;
data tras;
set tras;
drop _TYPE_ _FREQ_;
run;
proc sort data=tras TAGSORT;
by sno;
run;
proc sort data=&amp;amp;compname._trades1 TAGSORT;
by sno;
run;
proc sort data=&amp;amp;compname._ssnap TAGSORT;
by sno;
run;
data &amp;amp;compname._ssnap&amp;amp;i;
merge tras &amp;amp;compname._ssnap;
by sno;
run;
data &amp;amp;compname._ssnap&amp;amp;i;
set &amp;amp;compname._ssnap&amp;amp;i;
*if sno=sorno then do;
if stqs=. then stqs=0;
sq=sq-stqs;
* end;
keep sorno stype sp sq sdq sqo stime st sno;
run;
data &amp;amp;compname._ssnap&amp;amp;i;
set &amp;amp;compname._ssnap&amp;amp;i;
if sq&amp;lt;=0 then delete;
if st=. then delete;
run;
proc sort data=&amp;amp;compname._ssnap&amp;amp;i TAGSORT;
by sp st;
run;
data &amp;amp;compname._ssnap;
set &amp;amp;compname._ssnap&amp;amp;i;
run;
proc sort data=&amp;amp;compname._bsnap&amp;amp;i noduprecs TAGSORT;
by bno;
run;
proc sort data=&amp;amp;compname._bsnap&amp;amp;i TAGSORT;
by descending bp bt;
run;
proc sort data=&amp;amp;compname._ssnap&amp;amp;i noduprecs TAGSORT;
by sno;
run;
proc sort data=&amp;amp;compname._ssnap&amp;amp;i TAGSORT;
by sp st;
run;
data &amp;amp;compname._snap&amp;amp;i;
merge &amp;amp;compname._bsnap&amp;amp;i &amp;amp;compname._ssnap&amp;amp;i;
run;
data &amp;amp;compname._snap&amp;amp;i;
set &amp;amp;compname._snap&amp;amp;i;
tm1=&amp;amp;i;
date='01Jul2013'd;
format date date9.;
run;
proc append base=&amp;amp;compname._snap data=&amp;amp;compname._snap&amp;amp;i;
run;
data &amp;amp;compname._snap;
set &amp;amp;compname._snap;
tm= tm1+'09:15:00't;
format tm time8.;
run;
proc append base=mac.&amp;amp;compname._snap data=&amp;amp;compname._snap;
run;
proc sort data=mac.&amp;amp;compname._snap TAGSORT;
by date tm1;
run;
proc datasets nodetails nolist;
delete &amp;amp;compname._bord&amp;amp;i;
delete &amp;amp;compname._sord&amp;amp;i;
delete &amp;amp;compname._ssnap&amp;amp;i;
delete &amp;amp;compname._bsnap&amp;amp;i;
delete &amp;amp;compname._snap&amp;amp;i;

quit;
%end;
%end;
%mend omatching;
%omatching;

/* The Above code takes almost 16 Hrs to run */

/* The output of the above code will be used to compute the minute by minute spread of the stock. The spread computation code is shown below */

%macro spread(compname);
proc means data=AT.&amp;amp;compname._snap;
by tm;
var bp sp;
output out=AT.&amp;amp;Compname._bq max(bp)=bestbuy min(sp)=bestsell;
run;
%mend;
%spread(POWERGRID);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 05:39:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317499#M69530</guid>
      <dc:creator>rkdubey84</dc:creator>
      <dc:date>2016-12-08T05:39:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce the time taken in running the following code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317534#M69540</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This ia a question and answer forum, not a contract work request system. &amp;nbsp;We don't have the time to debug your process. &amp;nbsp;It is up to you to run through your code, step by step, and see what can be speeded up, improved.&lt;/P&gt;
&lt;P&gt;I have glanced over the first few blocks, and yes, there is quite a bit that can be re-programmed, and certainly a good dose of code formatting would make it a lot easier to read. &amp;nbsp;Some tips:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; list&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; 
&lt;SPAN class="token keyword"&gt;  input&lt;/SPAN&gt; names &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;20&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;index&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;names&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'&amp;amp;'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; names&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;tranwrd&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;names&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'&amp;amp;'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'and'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;index&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;names&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'-'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; names&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;tranwrd&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;names&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;'&lt;SPAN class="token operator"&gt;-&lt;/SPAN&gt;&lt;SPAN class="token datetime number"&gt;','d&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;');
  if index(names,'&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;') then names=tranwrd(names,'&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;&lt;SPAN class="token datetime number"&gt;','t&lt;/SPAN&gt;'&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;BR /&gt;  call execute(cats('%omatching (name=',names,');'));
&lt;SPAN class="token datalines"&gt;&lt;SPAN class="token keyword"&gt;datalines&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;SPAN class="token data string"&gt; 
POWERGRID
&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Would remove the need to create macro variables, do macro loops and such like. &amp;nbsp;The macro is called once per observation with the names variable.&lt;/P&gt;
&lt;PRE&gt;data &amp;amp;compname._trades;
  set mac.&amp;amp;compname.trades;
  tno=trdnum;
  bno=buyordnum;
  sno=sellordnum;
  format tradetime time8.;
  tp=tradeprice;
  tq=trdqty;
run;&lt;/PRE&gt;
&lt;P&gt;Why in the above are you setting new variables to be the same as other ones? &amp;nbsp;This is just duplicating the data making the datasets bigger than necessary. &amp;nbsp;Use rename=.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data &amp;amp;compname._trades;
  set &amp;amp;compname._trades;
  tt=tradetime-'09:15:00't;
  keep tt tp tq bno sno tno;
run;&lt;/PRE&gt;
&lt;P&gt;Why is this step needed at all, the above tt=, and the keep can be put in the previous datastep, therefore saving you a whole datestep.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anywhere, there is where I stop. &amp;nbsp;I would strongly suggest you start by taking one example, drop all the macro code, and then step through your code 1 at a time just running Base SAS code. &amp;nbsp;Identify what each datastep/procedure does, if it can be improved, dropped completely etc. then once you have the code as good as you can get it, then apply the macro part again. &amp;nbsp;This is all very symptomatic of coding without a plan, i.e. planning your code, modelling your data per a plan etc. this all helps to virtually remove the programming aspect.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 09:57:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317534#M69540</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-08T09:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce the time taken in running the following code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317543#M69545</link>
      <description>&lt;P&gt;Thanks RW9 for taking out valuable time from your busy schedule and trying to help me out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to assure you that what I am doing or requesting is not a part of "&lt;STRONG&gt;Contract Work Request System&lt;/STRONG&gt;" kind of thing.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My questions were fairly simple and indicated where the majority of the problem lies: "&lt;SPAN&gt;&lt;STRONG&gt;The time taken is mostly beacuse it sorts the dataset many times and everytime it reads and writes the dataset on to the machine hard disk&lt;/STRONG&gt;."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I had attached the entire code and dataset for better understanding of kind and helpful guys like you, and I also attached coz it suggested at the bottom of the request form to include the relavant data and code. I am extremely sorry if it appeared otherwise to you.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The Major Problem starts from the following part of the code where it sorts number of times as per the loop.&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%to&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;22501&lt;/SPAN&gt; &lt;SPAN class="token macroname"&gt;%by&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;60&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So,&lt;STRONG&gt;&amp;nbsp;&lt;/STRONG&gt;Basically I'm looking out for efficient sorting and data reading and writing suggestions. I tried TAGSORT option it didn't help. And index sorting I couldn't implement in this code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using the above code for analysing a part of my PhD Thesis work. I am not a SAS Certified professional and am learning bits and pieces from different sources including support.sas.com and communities.sas.com.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Thank You for your patience, time and help.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Good Day.&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 10:22:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317543#M69545</guid>
      <dc:creator>rkdubey84</dc:creator>
      <dc:date>2016-12-08T10:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce the time taken in running the following code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317544#M69546</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format your code, indent the sections and follow this guidelines for a start.&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi29/258-29.pdf" target="_self"&gt;Guidelines for Coding of SAS® Programs&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings12/257-2012.pdf" target="_self"&gt;50 Ways to Make Your SAS® Code Execute More Efficiently&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://support.sas.com/resources/papers/proceedings12/357-2012.pdf" target="_self"&gt;Top Ten SAS ® Performance Tuning Techniques&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Check how big your datasets are, and try to use a memlib instead of work.&lt;/P&gt;&lt;P&gt;You need to reduce the I/O operations and the amount of data beeing moved around.&lt;/P&gt;&lt;P&gt;Use where instead of if.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then ask again, by attaching your log and the text files if you didn't save at least half the process time.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 10:30:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317544#M69546</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2016-12-08T10:30:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce the time taken in running the following code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317545#M69547</link>
      <description>&lt;P&gt;Well, its not just a case of applying an option to a function. &amp;nbsp;The whole program needs addressing, not to mention the data moddeling which is there. &amp;nbsp;For instance, the part your raise:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macrostatement"&gt;%do&lt;/SPAN&gt; i&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt; &lt;SPAN class="token macrostatement"&gt;%to&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;22501&lt;/SPAN&gt; &lt;SPAN class="token macroname"&gt;%by&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;60&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is this, why 22501, why 60? &amp;nbsp;Why loop at all? &amp;nbsp;It looks like you blocking out hourly data, why? &amp;nbsp;Why not just create a variable with hour, then do your processing using by group? &amp;nbsp;That would be as fast as possible and simpler coding:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  hour=time / 60;  /* or whatever the number is to get hour */
run;

proc means data=want;
  by hour;
  var xyz;
run;
&lt;/PRE&gt;
&lt;P&gt;So in the above example (not tied to your one), I create a variable called hour, which would be 1, 2, 3 etc. depending on the time. &amp;nbsp;Then in the means I use this hour variable as a by group - no looping, and using the Base SAS functionality.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that the above is just one example, it would require going through the whole program, ensure the data is structured in the most efficient manner, there really is a lot that can be stripped out, or optimised - for instance as I was scrolling down I noticed this:&lt;/P&gt;
&lt;PRE&gt;data &amp;amp;compname._bsnap&amp;amp;i;
set &amp;amp;compname._bsnap&amp;amp;i;
if bq &amp;lt;= 0 then delete;
if bt=. then delete;
run;&lt;/PRE&gt;
&lt;P&gt;This could be re-written more efficiently as:&lt;/P&gt;
&lt;PRE&gt;data &amp;amp;compname._bsnap&amp;amp;i.;
  set &amp;amp;compname._bsnap&amp;amp;i. (where=(bg not in (0,.)));
run;&lt;/PRE&gt;
&lt;P&gt;But this also begs the question why this datastep is needed at all, it can just be included in one of the other steps.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Simply put, if you want an efficient program, then debugging is a step by step process. &amp;nbsp;If you just want things to run faster, then the simple answer is use smaller datasets or get a more powerful computer.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 10:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317545#M69547</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-08T10:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce the time taken in running the following code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317607#M69568</link>
      <description>&lt;P&gt;There is precious little you can do to optimize this code.&amp;nbsp; Really, you need to rip it up and rewrite it.&amp;nbsp; This logic processes the same data sets 375 times instead of once.&amp;nbsp; You need to figure out what it is supposed to do, then give the task to a SAS programmer who understands how to use a BY statement.&amp;nbsp; That being done, I would be surprised if the final version took more than 30 minutes to run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could tweak the existing code slightly by replacing some IF statements with WHERE statements.&amp;nbsp; But that would only make a minor impact.&amp;nbsp; If the program runs without TAGSORT, remove it.&amp;nbsp; TAGSORT takes longer to run, but allows programs to run that would otherwise run out of memory when sorting.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 14:08:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317607#M69568</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-08T14:08:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce the time taken in running the following code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317636#M69570</link>
      <description>&lt;P&gt;Why are there in excess of 88,000 data sets created? Lots of disk access for that.&lt;/P&gt;
&lt;P&gt;It really looks like someone does not know about SAS BY processing (and possibly the related First. and Last. processing)&amp;nbsp;and/or how to calculate offsets or the values of variables to hold those by values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Look at the code involving ._bord&amp;amp;i sets:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data &amp;amp;compname._bord&amp;amp;i;
set &amp;amp;compname._b;
if &amp;amp;tm-60 &amp;lt; bt &amp;lt;= &amp;amp;tm;
bno=borno;
run;

proc append base=&amp;amp;compname._bsnap data=&amp;amp;compname._bord&amp;amp;i force;
run;&lt;/PRE&gt;
&lt;P&gt;This looks like 1) subset the data from one set, set one variable and then 2) append them all to one set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am not quite sure why this is better then calculating one minimum value for &amp;amp;tm and the corresponding max and generate ONE set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also it looks likey you compile macros %borders and %sorders inside that loop 22,000+ times. Better would be to pull those macros out, define with appropriate parameters and compile once.&lt;/P&gt;</description>
      <pubDate>Thu, 08 Dec 2016 15:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317636#M69570</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-08T15:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to reduce the time taken in running the following code.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317793#M69603</link>
      <description>&lt;P&gt;Thank You&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/77163"&gt;@Oligolas&lt;/a&gt;&amp;nbsp;for your valuable inputs. I'll go ahead and try the suggestions that you have advised and will update you all of the progress.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you once again for being so patient and helpful.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Dec 2016 04:28:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-reduce-the-time-taken-in-running-the-following-code/m-p/317793#M69603</guid>
      <dc:creator>rkdubey84</dc:creator>
      <dc:date>2016-12-09T04:28:21Z</dc:date>
    </item>
  </channel>
</rss>

