<?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: Creating  a table using SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530401#M145033</link>
    <description>&lt;P&gt;Did you try running it? What happened?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But to answer your question, the code is not correct.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/148630"&gt;@fama&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a data set like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;V1&amp;nbsp; V2&amp;nbsp; v3&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want is:&lt;/P&gt;
&lt;P&gt;For each v1&amp;nbsp; in each v2 : I want to find distinct&amp;nbsp; v3 and then count them&amp;nbsp;( say we have 4 distinct value in V3 and each of them has different frequency) Then square each frequency and then sum up them&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Was wondering if the below code is right.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sql :&lt;/P&gt;
&lt;P&gt;create table X as select *,&amp;nbsp; &amp;nbsp; &amp;nbsp;sum ( count ( distinct v3))*2 ) as want&lt;/P&gt;
&lt;P&gt;group by V1 V2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help&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, 27 Jan 2019 02:34:08 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-01-27T02:34:08Z</dc:date>
    <item>
      <title>Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530399#M145031</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have a data set like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;V1&amp;nbsp; V2&amp;nbsp; v3&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 5&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 6&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is:&lt;/P&gt;&lt;P&gt;For each v1&amp;nbsp; in each v2 : I want to find distinct&amp;nbsp; v3 and then count them&amp;nbsp;( say we have 4 distinct value in V3 and each of them has different frequency) Then square each frequency and then sum up them&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Was wondering if the below code is right.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc sql :&lt;/P&gt;&lt;P&gt;create table X as select *,&amp;nbsp; &amp;nbsp; &amp;nbsp;sum ( count ( distinct v3))*2 ) as want&lt;/P&gt;&lt;P&gt;group by V1 V2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your help&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 02:14:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530399#M145031</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-27T02:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530401#M145033</link>
      <description>&lt;P&gt;Did you try running it? What happened?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But to answer your question, the code is not correct.&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/148630"&gt;@fama&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a data set like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;V1&amp;nbsp; V2&amp;nbsp; v3&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 5&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;2&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; 3&lt;/P&gt;
&lt;P&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want is:&lt;/P&gt;
&lt;P&gt;For each v1&amp;nbsp; in each v2 : I want to find distinct&amp;nbsp; v3 and then count them&amp;nbsp;( say we have 4 distinct value in V3 and each of them has different frequency) Then square each frequency and then sum up them&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Was wondering if the below code is right.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc sql :&lt;/P&gt;
&lt;P&gt;create table X as select *,&amp;nbsp; &amp;nbsp; &amp;nbsp;sum ( count ( distinct v3))*2 ) as want&lt;/P&gt;
&lt;P&gt;group by V1 V2;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your help&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, 27 Jan 2019 02:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530401#M145033</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-27T02:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530402#M145034</link>
      <description>I did not try. The data is quite big and it takes time to be ran.&lt;BR /&gt;I wanted to make sure if it is correct.&lt;BR /&gt;What is the correct one then?&lt;BR /&gt;Thanks</description>
      <pubDate>Sun, 27 Jan 2019 02:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530402#M145034</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-27T02:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530403#M145035</link>
      <description>&lt;P&gt;If the data is too big, try playing around with a subset instead.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the code to get a subset if you need that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input V1  V2  v3;
cards;
1      1    2
1      2    1
1      2    5
1      1    2
1      2    2
2     2     3
2     1    6
2     1    6
3     2    1
3     4    3
3     4    3
;;;;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
set have (obs=100);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Post &lt;STRONG&gt;exactly&lt;/STRONG&gt; you'd expect to see if your actual data was what you posted initially (my have data set) and I'll see what I can help you with.&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/148630"&gt;@fama&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I did not try. The data is quite big and it takes time to be ran.&lt;BR /&gt;I wanted to make sure if it is correct.&lt;BR /&gt;What is the correct one then?&lt;BR /&gt;Thanks&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 02:42:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530403#M145035</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-27T02:42:23Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530404#M145036</link>
      <description>The data is 170 GB!&lt;BR /&gt;Even finding the subset takes hours..&lt;BR /&gt;I will try thanks..&lt;BR /&gt;But what is wrong with the code?&lt;BR /&gt;</description>
      <pubDate>Sun, 27 Jan 2019 02:44:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530404#M145036</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-27T02:44:59Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530405#M145037</link>
      <description>&lt;P&gt;run your code using your sample and look at the output and see If it matches your expected result,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want us to provide you a solution, plz post the expected output for a prospective input&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 03:01:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530405#M145037</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-27T03:01:40Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530407#M145039</link>
      <description>Thanks for your reply:&lt;BR /&gt;Here is the data and expected output.&lt;BR /&gt;&lt;BR /&gt;data have;&lt;BR /&gt;input V1 V2 v3 want;&lt;BR /&gt;cards;&lt;BR /&gt;1 1 1 10&lt;BR /&gt;1 1 1 10&lt;BR /&gt;1 1 1 10&lt;BR /&gt;1 1 2 10&lt;BR /&gt;1 2 6 14&lt;BR /&gt;1 2 3 14&lt;BR /&gt;1 2 3 14&lt;BR /&gt;1 2 4 14&lt;BR /&gt;1 2 4 14&lt;BR /&gt;1 2 4 14&lt;BR /&gt;&lt;BR /&gt;;;;;&lt;BR /&gt;run;&lt;BR /&gt;10=( 3*2)+ (1*2) where 3 is the frequency of 1 in V3 and 1 is the frequency of 2 in V3&lt;BR /&gt;14= (1*2) +(2*2)+(3*2) where 1 is the frequency of 6 in V3 and 2 is the frequency of 3 in V3 and 3 is the frequency of 4&lt;BR /&gt;</description>
      <pubDate>Sun, 27 Jan 2019 03:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530407#M145039</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-27T03:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530410#M145040</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ok, how did you get the 10 and 14. What am i missing?&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/148630"&gt;@fama&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;10=( 3*2)+ (1*2)&lt;/STRONG&gt; where 3 is the frequency of 1 in V3 and 1 is the frequency of 2 in V3&lt;BR /&gt;&lt;STRONG&gt;14= (1*2) +(2*2)+(3*2)&lt;/STRONG&gt; where 1 is the frequency of 6 in V3 and 2 is the frequency of 3 in V3 and 3 is the frequency of 4&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 03:27:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530410#M145040</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-27T03:27:32Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530412#M145041</link>
      <description>we need to first look at V2. for each distinct value say 1 we count the distinct values of V3.&lt;BR /&gt;When V2 =1 , V3 has 1 (frequency =3) and 2(frequency =1).&lt;BR /&gt;then we need to obtain the square of each frequency that means 3*2 and 1*2 and sum up the results that means 9+1= 10&lt;BR /&gt;Hope it is clear&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Sun, 27 Jan 2019 03:35:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530412#M145041</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-27T03:35:45Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530413#M145042</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/148630"&gt;@fama&lt;/a&gt;&amp;nbsp; &amp;nbsp;Thank you &amp;amp; yes clear. One last question, do you really want this in proc sql?&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 03:59:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530413#M145042</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-27T03:59:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530414#M145043</link>
      <description>Sorry to get Square I should have used **.&lt;BR /&gt;&lt;BR /&gt;Yes I want to create a table using SQL in SAS</description>
      <pubDate>Sun, 27 Jan 2019 04:00:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530414#M145043</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-27T04:00:37Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530415#M145044</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input V1 V2 v3;
cards;
1 1 1 10
1 1 1 10
1 1 1 10
1 1 2 10
1 2 6 14
1 2 3 14
1 2 3 14
1 2 4 14
1 2 4 14
1 2 4 14
;;;;
run;

proc sql;
create table fama_want as
select a.*,want
from have a, (select v1,v2, sum(c) as want from (select *, count(v3)**2 as c from have group by v1, v2,v3 )
group by v1,v2) b
where a.v1=b.v1 and a.v2=b.v2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I might be away for supper and stuff. Let us know if you need some clarification&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 04:26:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530415#M145044</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-27T04:26:25Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530420#M145048</link>
      <description>Thank you very much Novinosrin.&lt;BR /&gt;I really appreciate your help.&lt;BR /&gt;The code works well.&lt;BR /&gt;Could you please clarify it for me. really like how it woks and learn...&lt;BR /&gt;Thanks again</description>
      <pubDate>Sun, 27 Jan 2019 05:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530420#M145048</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-27T05:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530422#M145050</link>
      <description>&lt;P&gt;I'm glad. It's almost midnight here. I'll leave some notes in the morning. Please don't mind. I promise i'll soon as I wake up&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 05:33:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530422#M145050</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-27T05:33:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530424#M145052</link>
      <description>&lt;P&gt;I would do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input V1 V2 v3;
cards;
1 1 1 
1 1 1 
1 1 1 
1 1 2 
1 2 6 
1 2 3 
1 2 3 
1 2 4 
1 2 4 
1 2 4 
;

proc sql;
select a.*, sumSqFreq
from
    have as a inner join
    ( select v1, v2, uss(freq) as sumSqFreq
      from 
        ( select v1, v2, v3, count(*) as freq
          from have
          group by v1, v2, v3 ) 
      group by v1, v2 ) as b 
    on a.v1=b.v1 and a.v2=b.v2;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Are you sure you need to remerge the statistics with the original data?&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 05:52:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530424#M145052</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-01-27T05:52:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530434#M145060</link>
      <description>Thank you PGStats for your reply and help.&lt;BR /&gt;Yes, I need the table for the next analysis.&lt;BR /&gt;</description>
      <pubDate>Sun, 27 Jan 2019 08:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530434#M145060</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-27T08:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530435#M145061</link>
      <description>I really appreciate it!</description>
      <pubDate>Sun, 27 Jan 2019 08:31:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530435#M145061</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-27T08:31:21Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530507#M145087</link>
      <description>&lt;P&gt;The logic works by&lt;/P&gt;
&lt;P&gt;1. steps of remerges to the original&lt;/P&gt;
&lt;P&gt;2. inner most inline view or easy to understand as sub query computes the frequency**2 and the next sub qery computes the sum of squared frequency.&lt;/P&gt;
&lt;P&gt;3. The computed sum of squares is then merged back with the original&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4. You deterine the above by starting from processing in hierarchical steps fromthe inner most sub query to the outer most for each level of computation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5. Best way to understand break each select clause and execute separately and view the results. You'll eventually get the hang of it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&lt;/P&gt;
&lt;P&gt;IMHO proc sql can take a bit longer to grasp as it's not intutive as a datastep for the reason datastep's sequential processing gives greater control. But sql is fun nonetheless&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 22:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530507#M145087</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-27T22:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530510#M145089</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/148630"&gt;@fama&lt;/a&gt;&amp;nbsp;just one clarification no one has mentioned, * is multiplication ** is power.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3*2=6&lt;/P&gt;
&lt;P&gt;3**2=9&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 22:48:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530510#M145089</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-01-27T22:48:56Z</dc:date>
    </item>
    <item>
      <title>Re: Creating  a table using SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530553#M145107</link>
      <description>Thank you&lt;BR /&gt;Maybe because I corrected this in one of my posts..</description>
      <pubDate>Mon, 28 Jan 2019 07:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-table-using-SQL/m-p/530553#M145107</guid>
      <dc:creator>fama</dc:creator>
      <dc:date>2019-01-28T07:57:34Z</dc:date>
    </item>
  </channel>
</rss>

