<?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: Base SAS tricky logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319543#M70216</link>
    <description>&lt;P&gt;If you have to handle really large datasets, some thoughts&lt;/P&gt;
&lt;P&gt;- reduce the length of the date variables; a length of 4 is sufficient.&lt;/P&gt;
&lt;P&gt;- always keep the minimum data necessary. That's why I did not include the + signs in the "products" string. Such things can be added at the end for display purposes. Make that collector string as short as necessary.&lt;/P&gt;
&lt;P&gt;- if you need to keep longer character variables, use the compress=yes option to reduce dataset size; if such datasets need to be sorted, using the tagsort option might make a sort feasible that crashes otherwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS is usually I/O intensive, so tuning a SAS server/computer is mostly done on the storage side.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Dec 2016 13:51:58 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2016-12-16T13:51:58Z</dc:date>
    <item>
      <title>Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319506#M70198</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm struck in coding below logic. Please help me out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have input data set of products and their usage across time. I need an output &amp;nbsp;in such a way that every overlapping of product &amp;nbsp; usage needs to be seen as seperate record. PFB example.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Input:&lt;/STRONG&gt;&lt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t;TD&gt;A&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10.01.2016&lt;/TD&gt;&lt;TD&gt;14.01.2016&lt;/TD&gt;&lt;TD&gt;A+B&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;15.01.2016&lt;/TD&gt;&lt;TD&gt;29.01.2016&lt;/TD&gt;&lt;TD&gt;A+B+C&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;30.01.2016&lt;/TD&gt;&lt;TD&gt;31.01.2016&lt;/TD&gt;&lt;TD&gt;A+C&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks alot.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 11:14:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319506#M70198</guid>
      <dc:creator>Ajay2</dc:creator>
      <dc:date>2016-12-16T11:14:40Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319508#M70200</link>
      <description>&lt;P&gt;Switch to a record for each day and then recombine into intervals.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 11:16:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319508#M70200</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-16T11:16:38Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319526#M70208</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm handling big data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I have to switch to one record for each day, will it be efficent?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 12:10:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319526#M70208</guid>
      <dc:creator>Ajay2</dc:creator>
      <dc:date>2016-12-16T12:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319528#M70209</link>
      <description>&lt;P&gt;Define "big data". How many billion records (because millions are not big)?&lt;/P&gt;
&lt;P&gt;Keep in mind that, during calculation of the time intervals, you need to keep only the necessary variables, resulting in small observation sizes.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 12:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319528#M70209</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-16T12:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319529#M70210</link>
      <description>&lt;P&gt;"big data" i mean to say not techinical term "big data".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;let me be clear, i'm handling huge data, I have around million records.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thnaks fro your reply.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 12:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319529#M70210</guid>
      <dc:creator>Ajay2</dc:creator>
      <dc:date>2016-12-16T12:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319530#M70211</link>
      <description>&lt;P&gt;A million records is puny when we're talking about SAS. So unless your server is twenty years old or severely misconfigured, no problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you still have doubts, you need to be more specific. eg post a proc contents output of your dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 12:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319530#M70211</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-16T12:23:52Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319534#M70212</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have swicthed to one record for each day. but I'm facing problem &amp;nbsp;in recombining them into intervals.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you please give me some sample code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 12:57:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319534#M70212</guid>
      <dc:creator>Ajay2</dc:creator>
      <dc:date>2016-12-16T12:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319538#M70213</link>
      <description>&lt;P&gt;Here is the complete code, from creating example data to final dataset:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id beginning_date :ddmmyy10. end_date :ddmmyy10. product $;
format beginning_date end_date ddmmyyp10.;
cards;
1 01.01.2016 31.01.2016 A
1 10.01.2016 29.01.2016 B
1 15.01.2016 31.01.2016 C
;
run;

data int1;
set have;
do prod_date = beginning_date to end_date;
  output;
end;
format prod_date ddmmyyp10.;
keep id prod_date product;
run;

proc sort data=int1;
by id prod_date product;
run;

data int2;
set int1;
by id prod_date;
retain products;
length products $10;
if first.prod_date then products = " ";
products = trim(products) !! product;
if last.prod_date then output;
keep id prod_date products;
run;

data want;
set int2;
by id products notsorted;
retain beginning_date;
format beginning_date end_date ddmmyyp10.;
if first.products then beginning_date = prod_date;
if last.products
then do;
  end_date = prod_date;
  output;
end;
keep id beginning_date end_date products;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The result:&lt;/P&gt;
&lt;PRE&gt;                  beginning_
id    products       date         end_date

 1      A         01.01.2016    09.01.2016
 1      AB        10.01.2016    14.01.2016
 1      ABC       15.01.2016    29.01.2016
 1      AC        30.01.2016    31.01.2016
&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Dec 2016 13:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319538#M70213</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-16T13:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319541#M70214</link>
      <description>&lt;P&gt;Hi Kurt,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks alot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is very helpful.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 13:38:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319541#M70214</guid>
      <dc:creator>Ajay2</dc:creator>
      <dc:date>2016-12-16T13:38:06Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319543#M70216</link>
      <description>&lt;P&gt;If you have to handle really large datasets, some thoughts&lt;/P&gt;
&lt;P&gt;- reduce the length of the date variables; a length of 4 is sufficient.&lt;/P&gt;
&lt;P&gt;- always keep the minimum data necessary. That's why I did not include the + signs in the "products" string. Such things can be added at the end for display purposes. Make that collector string as short as necessary.&lt;/P&gt;
&lt;P&gt;- if you need to keep longer character variables, use the compress=yes option to reduce dataset size; if such datasets need to be sorted, using the tagsort option might make a sort feasible that crashes otherwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS is usually I/O intensive, so tuning a SAS server/computer is mostly done on the storage side.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Dec 2016 13:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319543#M70216</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-16T13:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: Base SAS tricky logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319711#M70296</link>
      <description>&lt;P&gt;Of course,&lt;/P&gt;
&lt;P&gt;I would not miss such kind of question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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 have;
input id beginning_date :ddmmyy10. end_date :ddmmyy10. product $;
format beginning_date end_date ddmmyyp10.;
cards;
1 01.01.2016 31.01.2016 A
1 10.01.2016 29.01.2016 B
1 15.01.2016 31.01.2016 C
;
run;
data temp(index=(product xx=(id date)));
 set have;
 do date=beginning_date to end_date;
  output;
 end;
 drop beginning_date end_date;
run;
proc sql;
create table x as
 select distinct product from have;
quit;
data _null_;
 set x end=last;
 if _n_=1 then call execute('data all;merge ');
 call execute('temp(where=(p_'||put(_n_,8.-l)||'="'||product||'") 
 rename=(product=p_'||put(_n_,8.-l)||'))');
 if last then call execute(';by id date;length f $ 200;f=catx("+",of p_:); run;');
run;

data want;
 set all;
 by id f notsorted;
 retain first;
 if first.f then first=date;
 if last.f then do;begin_date=first;end_date=date;output; end;
 format date Begin_date end_date date9.;
 drop date p_: first;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Dec 2016 07:58:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Base-SAS-tricky-logic/m-p/319711#M70296</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-12-17T07:58:44Z</dc:date>
    </item>
  </channel>
</rss>

