<?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 Count cases within a variable and create new variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Count-cases-within-a-variable-and-create-new-variable/m-p/857471#M82475</link>
    <description>&lt;P&gt;Dear All Respected:&lt;/P&gt;&lt;P&gt;I have the following data that consists of three variables (ID and X1). However, I want to create a new variable (New-X1) that counts the same values of X1. Herewith I attached the example. Could you help me to give a SAS code that enables to execution of a new variable as shown in the format below?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lijuu_1-1675733197733.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80156iA0BD965D576933A3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Lijuu_1-1675733197733.png" alt="Lijuu_1-1675733197733.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;Best Regards.&lt;/P&gt;&lt;P&gt;Lijuu&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 07 Feb 2023 01:27:21 GMT</pubDate>
    <dc:creator>Lijuu</dc:creator>
    <dc:date>2023-02-07T01:27:21Z</dc:date>
    <item>
      <title>Count cases within a variable and create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-cases-within-a-variable-and-create-new-variable/m-p/857471#M82475</link>
      <description>&lt;P&gt;Dear All Respected:&lt;/P&gt;&lt;P&gt;I have the following data that consists of three variables (ID and X1). However, I want to create a new variable (New-X1) that counts the same values of X1. Herewith I attached the example. Could you help me to give a SAS code that enables to execution of a new variable as shown in the format below?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Lijuu_1-1675733197733.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/80156iA0BD965D576933A3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Lijuu_1-1675733197733.png" alt="Lijuu_1-1675733197733.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;Best Regards.&lt;/P&gt;&lt;P&gt;Lijuu&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 01:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-cases-within-a-variable-and-create-new-variable/m-p/857471#M82475</guid>
      <dc:creator>Lijuu</dc:creator>
      <dc:date>2023-02-07T01:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Count cases within a variable and create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-cases-within-a-variable-and-create-new-variable/m-p/857490#M82476</link>
      <description>&lt;P&gt;Pictures are extremely poor ways to share data. We cannot write code against picture. At least paste text. I am too lazy to retype pictures.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Something like this should work. Untested code as you did not provide data in a usable form, did not mention the name of your existing table so I use JUNK in the code below.&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table want as 
   select junk.*, count(x1) as new_x1
   from junk
   group by x1
   order by id
   ;
quit;&lt;/PRE&gt;
&lt;P&gt;The Select is asking for all the records and variables from junk and requesting a count of X1 as the new variable. The Group by says how to group records for the summary function Count, and the order is to maintain the original order of the data. The output order might end up different than expected.&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 05:50:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-cases-within-a-variable-and-create-new-variable/m-p/857490#M82476</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-02-07T05:50:41Z</dc:date>
    </item>
    <item>
      <title>Re: Count cases within a variable and create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-cases-within-a-variable-and-create-new-variable/m-p/857498#M82477</link>
      <description>&lt;P&gt;Dear ballardw:&lt;/P&gt;&lt;P&gt;Sorry for the uneditable data that I posted. Nevertheless, you did it and your code executed the expected outcome well.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 07 Feb 2023 07:50:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-cases-within-a-variable-and-create-new-variable/m-p/857498#M82477</guid>
      <dc:creator>Lijuu</dc:creator>
      <dc:date>2023-02-07T07:50:01Z</dc:date>
    </item>
    <item>
      <title>Re: Count cases within a variable and create new variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Count-cases-within-a-variable-and-create-new-variable/m-p/867697#M82626</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Dears:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have data in the following format:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Year&amp;nbsp; &amp;nbsp; Code&amp;nbsp; &amp;nbsp; Population&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000&amp;nbsp; &amp;nbsp;1001&amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000&amp;nbsp; &amp;nbsp;1001&amp;nbsp; &amp;nbsp; &amp;nbsp;15&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2001&amp;nbsp; &amp;nbsp;1001&amp;nbsp; &amp;nbsp; &amp;nbsp;4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2002&amp;nbsp; &amp;nbsp;1001&amp;nbsp; &amp;nbsp; &amp;nbsp;3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2002&amp;nbsp; &amp;nbsp;1001&amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000&amp;nbsp; &amp;nbsp;1002&amp;nbsp; &amp;nbsp; &amp;nbsp;5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000&amp;nbsp; &amp;nbsp;1002&amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2001&amp;nbsp; &amp;nbsp;1002&amp;nbsp; &amp;nbsp; &amp;nbsp;10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2002&amp;nbsp; &amp;nbsp;1002&amp;nbsp; &amp;nbsp; &amp;nbsp;25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2002&amp;nbsp; 1002&amp;nbsp; &amp;nbsp; &amp;nbsp; 30&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to have a total population per year and code it as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Year&amp;nbsp; Code Population&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000&amp;nbsp; &amp;nbsp;1001&amp;nbsp; &amp;nbsp;25&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2001&amp;nbsp; &amp;nbsp;1001&amp;nbsp; &amp;nbsp; 4&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2002&amp;nbsp; &amp;nbsp;1001&amp;nbsp; &amp;nbsp; 8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2000&amp;nbsp; &amp;nbsp;1002&amp;nbsp; &amp;nbsp; 13&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2001&amp;nbsp; &amp;nbsp;1002&amp;nbsp; &amp;nbsp; 10&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2002&amp;nbsp; &amp;nbsp;1002&amp;nbsp; &amp;nbsp; 55&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And finally, I want to transpose the total population per year as&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Code&amp;nbsp; Population_2000&amp;nbsp; Population_2001&amp;nbsp; Population_2002&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1001&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;25&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;8&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1002&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;13&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;55&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you very much for your help.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Lijalem&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 03 Apr 2023 04:08:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Count-cases-within-a-variable-and-create-new-variable/m-p/867697#M82626</guid>
      <dc:creator>Lijuu</dc:creator>
      <dc:date>2023-04-03T04:08:38Z</dc:date>
    </item>
  </channel>
</rss>

