<?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: Monotonic function with group by proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Monotonic-function-with-group-by-proc-sql/m-p/371171#M88662</link>
    <description>&lt;P&gt;Please follow the guidance next to Post button when you start a new question. &amp;nbsp;Post example test data in the form of a datastep, and show what you want out. &amp;nbsp;Explain any logic between the two, this avoids us guessing what you want to do. &amp;nbsp;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;&amp;nbsp;has shown datastep would be simpler for this task, a minor update to use the binary functions:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;&lt;BR /&gt;  by year;
  n=ifn(first.year,1,sum(n,1));
run;&lt;/PRE&gt;
&lt;P&gt;I note all of your questions are about SQL, is there a reason you avoid using Base SAS? &amp;nbsp;You will find that both have their benefits - SQL for instance does not care about sort on its data as it does it internally, datastep is good at linear steps through data such as this problem. &amp;nbsp;Unless you connect to a database there really is no need to limit yourself to one or the other.&lt;/P&gt;</description>
    <pubDate>Wed, 28 Jun 2017 08:33:20 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-06-28T08:33:20Z</dc:date>
    <item>
      <title>Monotonic function with group by proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Monotonic-function-with-group-by-proc-sql/m-p/371135#M88657</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create a monotonic() function that would go from 1 to n based on another variable such that if i have a dataset with years, it goes from 1 to x for 2012, 1 to y for 2013, 1 to z for 2014 and so on... is there a way to acheive that? I tried the "group" by function but no luck!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql; 
create table want as select 
year, 
name, 
score, 
monotonic() as row
from have;
quit; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 28 Jun 2017 05:08:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Monotonic-function-with-group-by-proc-sql/m-p/371135#M88657</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-06-28T05:08:48Z</dc:date>
    </item>
    <item>
      <title>Re: Monotonic function with group by proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Monotonic-function-with-group-by-proc-sql/m-p/371137#M88659</link>
      <description>&lt;P&gt;Something like this by datastep. if you can show a sample of have and want that would make it easier.&lt;/P&gt;
&lt;PRE&gt;data have;
 input year name $;
 datalines;
 2014 sam
 2014 ram
 2014 kam
 2013 nam
 2013 bam
 2013 lam
 ;
run;

proc sort data =have;
by year name;
run;

data want;
set have;
by year;
if first.year then sum=1;
else sum+1;
run;&lt;BR /&gt;&lt;BR /&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 06:41:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Monotonic-function-with-group-by-proc-sql/m-p/371137#M88659</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2017-06-28T06:41:51Z</dc:date>
    </item>
    <item>
      <title>Re: Monotonic function with group by proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Monotonic-function-with-group-by-proc-sql/m-p/371171#M88662</link>
      <description>&lt;P&gt;Please follow the guidance next to Post button when you start a new question. &amp;nbsp;Post example test data in the form of a datastep, and show what you want out. &amp;nbsp;Explain any logic between the two, this avoids us guessing what you want to do. &amp;nbsp;As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37783"&gt;@kiranv_&lt;/a&gt;&amp;nbsp;has shown datastep would be simpler for this task, a minor update to use the binary functions:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;&lt;BR /&gt;  by year;
  n=ifn(first.year,1,sum(n,1));
run;&lt;/PRE&gt;
&lt;P&gt;I note all of your questions are about SQL, is there a reason you avoid using Base SAS? &amp;nbsp;You will find that both have their benefits - SQL for instance does not care about sort on its data as it does it internally, datastep is good at linear steps through data such as this problem. &amp;nbsp;Unless you connect to a database there really is no need to limit yourself to one or the other.&lt;/P&gt;</description>
      <pubDate>Wed, 28 Jun 2017 08:33:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Monotonic-function-with-group-by-proc-sql/m-p/371171#M88662</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-06-28T08:33:20Z</dc:date>
    </item>
    <item>
      <title>Re: Monotonic function with group by proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Monotonic-function-with-group-by-proc-sql/m-p/371262#M88675</link>
      <description>Thank you! I'll note that for the future. I am more familiar with SQL and the data I use is most often from data warehouse-type sources.</description>
      <pubDate>Wed, 28 Jun 2017 12:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Monotonic-function-with-group-by-proc-sql/m-p/371262#M88675</guid>
      <dc:creator>camfarrell25</dc:creator>
      <dc:date>2017-06-28T12:49:24Z</dc:date>
    </item>
  </channel>
</rss>

