<?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: Can anyone help me with this programming problem in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526673#M5132</link>
    <description>&lt;P&gt;If I understand the problem, it seems like SQL is the wrong tool to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems like you need to loop over i going 1 to N and j going 1 to N without i=j&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this, assuming N=20:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     set have;
     array dt_sold dt_sold1-dt_sold20;
     array dt_cre dt_cre1-dt_cre20;
     array dt_exp dt_exp1-dt_exp20;
     sum=0;
     do i=1 to N
          do j=1 to N;
               if i^=j then do;
                     /* your formula goes here */
                     /* this is just an example: */
                     sum=sum + min(dt_sold(i),dt_sold(j)) - 
                           max(dt_cre(i),dt_sold(j));
               end;
           end;
       end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 13 Jan 2019 01:18:41 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2019-01-13T01:18:41Z</dc:date>
    <item>
      <title>Can anyone help me with this programming problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526671#M5130</link>
      <description>&lt;P&gt;Hi, dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you first for helping me with this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a new variable calculating the following equation:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;X=sum {min(dt_sold(i), dt_sold(j)) - max(dt_cre(i), dt_sold(j))} if dt_sold(i) or dt_sold(j) is missing, use dt_exp(i) or dt_exp(j) instead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i and j are the unique id number of each transaction, and i does not equal to j.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I expect to run i from 1 to N and j from 1 to N.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;transaction j has to satisfy other condition such as d_fsa (i) = d_fsa (j).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table table1 as
select unique la1.*, sum(min(la1.date_sold, past1.date_sold)-max(la1.date_cre, past1.date_cre)) as o1
from la1
left join
la1 past1
on (la1.d_fsa=past1.d_fsa)
group by 1
order by 1 ;
quit; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I try my best to write the above code, but I know it is wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me with the code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Freda&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 12 Jan 2019 23:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526671#M5130</guid>
      <dc:creator>freda</dc:creator>
      <dc:date>2019-01-12T23:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Can anyone help me with this programming problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526673#M5132</link>
      <description>&lt;P&gt;If I understand the problem, it seems like SQL is the wrong tool to do this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It seems like you need to loop over i going 1 to N and j going 1 to N without i=j&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this, assuming N=20:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     set have;
     array dt_sold dt_sold1-dt_sold20;
     array dt_cre dt_cre1-dt_cre20;
     array dt_exp dt_exp1-dt_exp20;
     sum=0;
     do i=1 to N
          do j=1 to N;
               if i^=j then do;
                     /* your formula goes here */
                     /* this is just an example: */
                     sum=sum + min(dt_sold(i),dt_sold(j)) - 
                           max(dt_cre(i),dt_sold(j));
               end;
           end;
       end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Jan 2019 01:18:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526673#M5132</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-13T01:18:41Z</dc:date>
    </item>
    <item>
      <title>Re: Can anyone help me with this programming problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526694#M5140</link>
      <description>Hi, my variable dt_sold is only one variable with 10 observations. with your code, the sas generate 20 variables from dt_sold1 to dt_sold20. I want to compare cross observations not cross variables. i and j are the ith observation and jth observation.&lt;BR /&gt;&lt;BR /&gt;Thank you&lt;BR /&gt;&lt;BR /&gt;Best,&lt;BR /&gt;&lt;BR /&gt;Yanting</description>
      <pubDate>Sun, 13 Jan 2019 03:30:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526694#M5140</guid>
      <dc:creator>freda</dc:creator>
      <dc:date>2019-01-13T03:30:37Z</dc:date>
    </item>
    <item>
      <title>Re: Can anyone help me with this programming problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526745#M5161</link>
      <description>&lt;P&gt;Show us a portion of your data so we can see what it looks like so we can figure out how to write the code.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jan 2019 17:15:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526745#M5161</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-01-13T17:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Can anyone help me with this programming problem</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526759#M5162</link>
      <description>&lt;P&gt;For your Excel data, show what you would expect as the output.&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/224413"&gt;@freda&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi, dear all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you first for helping me with this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a new variable calculating the following equation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;X=sum {min(dt_sold(i), dt_sold(j)) - max(dt_cre(i), dt_sold(j))} if dt_sold(i) or dt_sold(j) is missing, use dt_exp(i) or dt_exp(j) instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;i and j are the unique id number of each transaction, and i does not equal to j.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I expect to run i from 1 to N and j from 1 to N.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;transaction j has to satisfy other condition such as d_fsa (i) = d_fsa (j).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table table1 as
select unique la1.*, sum(min(la1.date_sold, past1.date_sold)-max(la1.date_cre, past1.date_cre)) as o1
from la1
left join
la1 past1
on (la1.d_fsa=past1.d_fsa)
group by 1
order by 1 ;
quit; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I try my best to write the above code, but I know it is wrong.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone help me with the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you so much&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Freda&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jan 2019 19:04:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Can-anyone-help-me-with-this-programming-problem/m-p/526759#M5162</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-13T19:04:21Z</dc:date>
    </item>
  </channel>
</rss>

