<?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: sort by multiple variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496709#M131423</link>
    <description>&lt;P&gt;That's fine as long as you have a maximum of 2 months per ID.&amp;nbsp; Once you hit 3 months per ID, you have to account for a flag pattern like 1 0 1.&lt;/P&gt;</description>
    <pubDate>Tue, 18 Sep 2018 19:17:14 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-09-18T19:17:14Z</dc:date>
    <item>
      <title>sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496671#M131402</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset after I sorted by id date,&amp;nbsp;results looks like&amp;nbsp;below:&lt;/P&gt;&lt;P&gt;date&amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp; &amp;nbsp;flag&lt;/P&gt;&lt;P&gt;JAN&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;FEB&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;JAN&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;FEB&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;JAN&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;FEB&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to see:&amp;nbsp; first flag=1 group by id date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;date&amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp; &amp;nbsp;flag&amp;nbsp; &amp;nbsp;flag1&lt;/P&gt;&lt;P&gt;JAN&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;FEB&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;JAN&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;FEB&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;JAN&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;FEB&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My code failed:&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;set old;&lt;/P&gt;&lt;P&gt;by id date flag;&lt;/P&gt;&lt;P&gt;if first.flag=1 then flag1=1;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;anyone knows how to get data I want? Thank you so much!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 18:33:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496671#M131402</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-18T18:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496675#M131404</link>
      <description>&lt;P&gt;are you missing&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;retain flag1;&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 18:39:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496675#M131404</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-18T18:39:12Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496681#M131408</link>
      <description>&lt;P&gt;no. I just want to denote every first flag=1 corrurance and let it be flag1=1.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 18:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496681#M131408</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-18T18:42:59Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496682#M131409</link>
      <description>&lt;P&gt;Try it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;retain dummy;&lt;/P&gt;
&lt;P&gt;if first.id then dummy=flag;&lt;/P&gt;
&lt;P&gt;else dummy + flag;&lt;/P&gt;
&lt;P&gt;if dummy=1 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;flag1=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;dummy=2;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop dummy;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 18:43:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496682#M131409</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-18T18:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496683#M131410</link>
      <description>&lt;P&gt;is this your &lt;STRONG&gt;want&lt;/STRONG&gt;?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;date&amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp; &amp;nbsp;flag&amp;nbsp; &amp;nbsp;flag1&lt;/P&gt;
&lt;P&gt;JAN&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;FEB&amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;JAN&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;
&lt;P&gt;FEB&amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;
&lt;P&gt;JAN&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;
&lt;P&gt;FEB&amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 18:44:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496683#M131410</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-18T18:44:21Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496689#M131414</link>
      <description>yes</description>
      <pubDate>Tue, 18 Sep 2018 18:50:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496689#M131414</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-18T18:50:36Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496700#M131419</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date $   id     flag;
cards;
JAN    1      0
FEB    1      0
JAN    2      1
FEB    2      1
JAN    3      0
FEB    3      1
;

data want;

set have;

by id  flag notsorted ;

if first.flag and flag=1 then flag1=1; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Sep 2018 19:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496700#M131419</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-18T19:03:58Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496709#M131423</link>
      <description>&lt;P&gt;That's fine as long as you have a maximum of 2 months per ID.&amp;nbsp; Once you hit 3 months per ID, you have to account for a flag pattern like 1 0 1.&lt;/P&gt;</description>
      <pubDate>Tue, 18 Sep 2018 19:17:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496709#M131423</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-18T19:17:14Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496712#M131435</link>
      <description>Thank you &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&lt;BR /&gt;result from your code&lt;BR /&gt;date id flag flag1&lt;BR /&gt;&lt;BR /&gt;JAN 1 0&lt;BR /&gt;&lt;BR /&gt;FEB 1 0&lt;BR /&gt;&lt;BR /&gt;JAN 2 1 1&lt;BR /&gt;&lt;BR /&gt;FEB 2 1 1&lt;BR /&gt;&lt;BR /&gt;JAN 3 0&lt;BR /&gt;&lt;BR /&gt;FEB 3 1 1&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;but how to not retain 1 for every id, I just need first flag=1 to be denoted. Thanks!</description>
      <pubDate>Tue, 18 Sep 2018 19:32:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496712#M131435</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-18T19:32:38Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496713#M131436</link>
      <description>I have a dataset with million dataset, I just set an example for the situation I try to get.</description>
      <pubDate>Tue, 18 Sep 2018 19:46:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496713#M131436</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-18T19:46:05Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496795#M131486</link>
      <description>&lt;P&gt;This one uses virtually the same logic as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;.&amp;nbsp; I put it in for variety, and a&amp;nbsp;possible&amp;nbsp;unreasonable regard for compactness.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input date $   id     flag;
cards;
JAN    1      0
FEB    1      0
JAN    2      1
FEB    2      1
JAN    3      0
FEB    3      1
;

data want (drop=n_ones);
  set have;
  by id flag;

  if first.id then n_ones=0;
  n_ones+flag;
  flag1= ifn(flag=1 and n_ones=1,1,0);
run;    &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Sep 2018 23:47:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496795#M131486</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-18T23:47:45Z</dc:date>
    </item>
    <item>
      <title>Re: sort by multiple variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496958#M131566</link>
      <description>Thank you!</description>
      <pubDate>Wed, 19 Sep 2018 13:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-by-multiple-variable/m-p/496958#M131566</guid>
      <dc:creator>jojozheng</dc:creator>
      <dc:date>2018-09-19T13:24:30Z</dc:date>
    </item>
  </channel>
</rss>

