<?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: Alternate gender in output in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352422#M82147</link>
    <description>Thanks got your Point Naveen</description>
    <pubDate>Sat, 22 Apr 2017 12:44:11 GMT</pubDate>
    <dc:creator>Nitish1003</dc:creator>
    <dc:date>2017-04-22T12:44:11Z</dc:date>
    <item>
      <title>Alternate gender in output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352416#M82141</link>
      <description>&lt;P&gt;Need a help to generate alternate gender output.&lt;/P&gt;&lt;P&gt;Dataset :-&lt;/P&gt;&lt;P&gt;data new;&lt;BR /&gt;input id gender $;&lt;BR /&gt;datalines ;&lt;BR /&gt;1 M&lt;BR /&gt;2 M&lt;BR /&gt;3 M&lt;BR /&gt;4 F&lt;BR /&gt;5 F&lt;BR /&gt;6 F&lt;BR /&gt;7 M&lt;BR /&gt;8 F&lt;BR /&gt;;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Output :-&lt;/P&gt;&lt;P&gt;1 M&lt;BR /&gt;4 F&lt;BR /&gt;2 M&lt;BR /&gt;5 F&lt;BR /&gt;3 M&lt;BR /&gt;6 F&lt;BR /&gt;7 M&lt;BR /&gt;8 F&lt;/P&gt;&lt;P&gt;Please let me know how can i achieve it&lt;/P&gt;&lt;P&gt;Regards&lt;/P&gt;&lt;P&gt;Nitish&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2017 12:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352416#M82141</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-04-22T12:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Alternate gender in output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352417#M82142</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;&lt;P&gt;merge new(where=(gender='M')) new(rename=(id=_id gender=_gender) where=(_gender='F'));&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;gender=_gender ;&lt;/P&gt;&lt;P&gt;id=_id;&lt;/P&gt;&lt;P&gt;output;&lt;/P&gt;&lt;P&gt;drop _:;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2017 12:26:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352417#M82142</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-22T12:26:02Z</dc:date>
    </item>
    <item>
      <title>Re: Alternate gender in output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352418#M82143</link>
      <description>&lt;P&gt;What is the purpose of this? And what if there were an unequal amount of M vs F?&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2017 12:26:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352418#M82143</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-04-22T12:26:26Z</dc:date>
    </item>
    <item>
      <title>Re: Alternate gender in output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352419#M82144</link>
      <description>Hi Naveen&lt;BR /&gt;Thanks for the help. Can you please let me know the logic how this code works.&lt;BR /&gt;Regards&lt;BR /&gt;Nitish</description>
      <pubDate>Sat, 22 Apr 2017 12:30:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352419#M82144</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-04-22T12:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Alternate gender in output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352420#M82145</link>
      <description>&lt;P&gt;I am not great at explaining as i am not smart. But here you go,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;i. split the two into 2 datasets and apply filters on M and F to get them in sequence.&lt;/P&gt;&lt;P&gt;ii. Now you have both in the PDV&lt;/P&gt;&lt;P&gt;iii. In order, to avoid overwriting the values with common names, rename them before taking them to PDV&lt;/P&gt;&lt;P&gt;iv. Reset the values in the left table with the values in the right table on the 2nd explicit output after you have written the 1st explicit output.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;HTH,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2017 12:35:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352420#M82145</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-04-22T12:35:21Z</dc:date>
    </item>
    <item>
      <title>Re: Alternate gender in output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352422#M82147</link>
      <description>Thanks got your Point Naveen</description>
      <pubDate>Sat, 22 Apr 2017 12:44:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352422#M82147</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-04-22T12:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: Alternate gender in output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352428#M82148</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I'm still not sure what the purpose is of doing this, but you are right that with an uneven number of males and females the merge approach might not work as desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; However, there is a much simpler approach that takes care of the uneven number of males and females and does not require a merge. Basically, you create a "helper" variable based on the gender where you are always incrementing a counter for males by 1 and incrementing the counter for females by 1.01. Then, you make a new counter to be the new order variable and sort by that order variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; For example, here's the code to read the data which is also making the helper variables, MORD, FORD and NEWORD:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data new;
input id gender $;
origord = _n_;
if gender = 'M' then do; 
  mord+1; 
  neword = mord; 
end;
else if gender='F' then do; 
  ford+1.01; 
  neword=ford; 
end;
datalines ;
1 M
2 M
3 M
4 F
5 F
6 F
7 M
8 F
9 F
10 M
11 F
;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then, after this step, you have this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8485i21F5E23715E86FEB/image-size/original?v=1.0&amp;amp;px=-1" alt="before_sort.png" title="before_sort.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;Note that I added some extra rows with an uequal number of males and females to test the scenario.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then, all you have to do is sort by the NEWORD variable:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/8486i26361E8D6BD84DA3/image-size/original?v=1.0&amp;amp;px=-1" alt="after_sort.png" title="after_sort.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No merge needed at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;</description>
      <pubDate>Sat, 22 Apr 2017 14:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352428#M82148</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-04-22T14:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Alternate gender in output</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352452#M82155</link>
      <description>Thanks for the help.&lt;BR /&gt;I am just trying to learn sas.</description>
      <pubDate>Sat, 22 Apr 2017 17:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Alternate-gender-in-output/m-p/352452#M82155</guid>
      <dc:creator>Nitish1003</dc:creator>
      <dc:date>2017-04-22T17:12:02Z</dc:date>
    </item>
  </channel>
</rss>

