<?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 print obserbations or rownumber for PROC SQL procedure in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722805#M27927</link>
    <description>&lt;P&gt;See this short example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pnq;
input abc $ xyz $ dep $ sal;
datalines;
A A xxx 1
A A xxx 2
A A Y 5
B B xxx 6
B B Z 7
;


PROC SQL;
SELECT ABC,XYZ, DEP,Sum(SAL)as Sal
from PNQ
where DEP='xxx'
group by ABC,XYZ;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log from the SQL:&lt;/P&gt;
&lt;PRE&gt; 84         PROC SQL;
 85         SELECT ABC,XYZ, DEP,Sum(SAL)as Sal
 86         from PNQ
 87         where DEP='xxx'
 88         group by ABC,XYZ;
 NOTE: The query requires &lt;FONT color="#FF0000"&gt;remerging&lt;/FONT&gt; summary statistics back with the original data.
 89         Quit;
&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;abc	xyz	dep	Sal
A	A	xxx	3
A	A	xxx	3
B	B	xxx	6
&lt;/PRE&gt;
&lt;P&gt;As you can see, you get two lines for the first group, instead of only one with the sum. Is this your intention?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No matter what, a result like this with a row number can be done with PROC PRINT. A dataset with a running count is done best in a data step.&lt;/P&gt;
&lt;P&gt;Maxim 14: Use the Right Tool.&lt;/P&gt;
&lt;P&gt;Most often, SQL is NOT the right tool.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For more help, please supply example data in&amp;nbsp;a data step with datalines (see my code example), and show the exact expected result from this, and declare if you want a report or a dataset.&lt;/P&gt;</description>
    <pubDate>Tue, 02 Mar 2021 08:33:35 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-03-02T08:33:35Z</dc:date>
    <item>
      <title>How to print obserbations or rownumber for PROC SQL procedure</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722284#M27888</link>
      <description>&lt;P&gt;Hi I have PROC SQL procedure with SELECT SQL code , I would like to print SLNO or observation number when PROC SQL SELECT query executes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;SELECT ABC,XYZ, DEP,Sum(SAL)as Sal&lt;/P&gt;&lt;P&gt;from PNQ&lt;/P&gt;&lt;P&gt;where DEP='xxx'&lt;/P&gt;&lt;P&gt;group by ABC,XYZ;&lt;/P&gt;&lt;P&gt;Quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to print the results with SL no , don't want to create SAS data set for this, Is there any other approach we can get Select SQL with sl or observation number printed on output results.?&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;</description>
      <pubDate>Fri, 26 Feb 2021 23:57:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722284#M27888</guid>
      <dc:creator>Ashpak</dc:creator>
      <dc:date>2021-02-26T23:57:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to print obserbations or rownumber for PROC SQL procedure</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722285#M27889</link>
      <description>&lt;P&gt;Do you expect this to be the "row number" in the source data set or in the result of the query?&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 00:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722285#M27889</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-27T00:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to print obserbations or rownumber for PROC SQL procedure</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722286#M27890</link>
      <description>No Just in the result Query</description>
      <pubDate>Sat, 27 Feb 2021 00:06:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722286#M27890</guid>
      <dc:creator>Ashpak</dc:creator>
      <dc:date>2021-02-27T00:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to print obserbations or rownumber for PROC SQL procedure</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722319#M27893</link>
      <description>&lt;P&gt;There is an undocumented SAS function called MONOTONIC that will accomplish this. See the following example:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table junk as 
   select sex,age, mean(weight) as mweight, monotonic() as n
   from sashelp.class
   group by sex, age
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;Undocumented means that behavior is somewhat unpredictable in some situations and may disappear at any time when SAS upgrades so is really not recommended in production jobs.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 06:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722319#M27893</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-02-27T06:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: How to print obserbations or rownumber for PROC SQL procedure</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722327#M27894</link>
      <description>&lt;P&gt;Do you actually want the remerge, or do you want a single line per abc,xyz?&lt;/P&gt;</description>
      <pubDate>Sat, 27 Feb 2021 12:26:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722327#M27894</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-02-27T12:26:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to print obserbations or rownumber for PROC SQL procedure</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722741#M27914</link>
      <description>&lt;P&gt;I just want normal sql code results with observation slno, example if the PROC SQL procedure returns 10 records&amp;nbsp; then I should get with printed each records with SLno or observation no.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 23:50:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722741#M27914</guid>
      <dc:creator>Ashpak</dc:creator>
      <dc:date>2021-03-01T23:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to print obserbations or rownumber for PROC SQL procedure</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722805#M27927</link>
      <description>&lt;P&gt;See this short example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data pnq;
input abc $ xyz $ dep $ sal;
datalines;
A A xxx 1
A A xxx 2
A A Y 5
B B xxx 6
B B Z 7
;


PROC SQL;
SELECT ABC,XYZ, DEP,Sum(SAL)as Sal
from PNQ
where DEP='xxx'
group by ABC,XYZ;
Quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log from the SQL:&lt;/P&gt;
&lt;PRE&gt; 84         PROC SQL;
 85         SELECT ABC,XYZ, DEP,Sum(SAL)as Sal
 86         from PNQ
 87         where DEP='xxx'
 88         group by ABC,XYZ;
 NOTE: The query requires &lt;FONT color="#FF0000"&gt;remerging&lt;/FONT&gt; summary statistics back with the original data.
 89         Quit;
&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;abc	xyz	dep	Sal
A	A	xxx	3
A	A	xxx	3
B	B	xxx	6
&lt;/PRE&gt;
&lt;P&gt;As you can see, you get two lines for the first group, instead of only one with the sum. Is this your intention?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No matter what, a result like this with a row number can be done with PROC PRINT. A dataset with a running count is done best in a data step.&lt;/P&gt;
&lt;P&gt;Maxim 14: Use the Right Tool.&lt;/P&gt;
&lt;P&gt;Most often, SQL is NOT the right tool.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For more help, please supply example data in&amp;nbsp;a data step with datalines (see my code example), and show the exact expected result from this, and declare if you want a report or a dataset.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 08:33:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-to-print-obserbations-or-rownumber-for-PROC-SQL-procedure/m-p/722805#M27927</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-02T08:33:35Z</dc:date>
    </item>
  </channel>
</rss>

