<?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: Convert sub total / summary rows to a variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644776#M78490</link>
    <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;. Sorry for the ambiguity. The values that variable municipality takes don't share prefix: district but different district names. There are 9 districts that I could specify for the 'find' function. But some cities takes same names as their districts. Is there any solution to the update problem?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input municipality : $9. count pop rate;
cards;
Daejeon 1000 10000 10
A_city 300 2500 12
Daejeon 200 6000 3.3
B_city 500 1500 33.3
Busan 100 500 20
C_city 50 200 25
Busan 50 300 16.7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 02 May 2020 19:22:07 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2020-05-02T19:22:07Z</dc:date>
    <item>
      <title>Convert sub total / summary rows to a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644757#M78488</link>
      <description>&lt;P&gt;Hi Folks:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could you please help me convert summary rows under municipality column (Current structure) to a variable shown as 'district' (Desired output) in the image below? I need district names as 'ID1NAME' variable and city names as 'IDNAME' variable for the ensuing data linkages.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="table wanted.png" style="width: 660px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39004i0266BDDA57B24F65/image-size/large?v=v2&amp;amp;px=999" role="button" title="table wanted.png" alt="table wanted.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input municipality : $9. count pop rate;
cards;
district1 1000 10000 10
city1 300 2500 12
city2 200 6000 3.3
city3 500 1500 33.3
district2 100 500 20
city4 50 200 25
city5 50 300 16.7
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 02 May 2020 18:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644757#M78488</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-05-02T18:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Convert sub total / summary rows to a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644764#M78489</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/132289"&gt;@Cruise&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do this, using the retain statement:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	length ID1NAME $ 20;
	set have;
	retain ID1NAME;
	if find(municipality,"district")&amp;gt;0 then do;
		ID1NAME=municipality;
		delete;
	end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-left" image-alt="Capture d’écran 2020-05-02 à 20.39.05.png" style="width: 291px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/39006i1C455C2691243548/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture d’écran 2020-05-02 à 20.39.05.png" alt="Capture d’écran 2020-05-02 à 20.39.05.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 02 May 2020 18:39:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644764#M78489</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-05-02T18:39:28Z</dc:date>
    </item>
    <item>
      <title>Re: Convert sub total / summary rows to a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644776#M78490</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292097"&gt;@ed_sas_member&lt;/a&gt;&amp;nbsp;. Sorry for the ambiguity. The values that variable municipality takes don't share prefix: district but different district names. There are 9 districts that I could specify for the 'find' function. But some cities takes same names as their districts. Is there any solution to the update problem?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input municipality : $9. count pop rate;
cards;
Daejeon 1000 10000 10
A_city 300 2500 12
Daejeon 200 6000 3.3
B_city 500 1500 33.3
Busan 100 500 20
C_city 50 200 25
Busan 50 300 16.7
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 02 May 2020 19:22:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644776#M78490</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-05-02T19:22:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert sub total / summary rows to a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644783#M78491</link>
      <description>&lt;P&gt;Given your structure, there is nothing to discern a district observation from a city observation as soon as they have the same name.&lt;/P&gt;</description>
      <pubDate>Sat, 02 May 2020 21:02:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644783#M78491</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-02T21:02:51Z</dc:date>
    </item>
    <item>
      <title>Re: Convert sub total / summary rows to a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644785#M78492</link>
      <description>True, however, District gets the sum value of cities combined, or mean rates of cities combined. Can this logic be used here?</description>
      <pubDate>Sat, 02 May 2020 21:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/644785#M78492</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2020-05-02T21:42:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert sub total / summary rows to a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/645002#M78506</link>
      <description>&lt;P&gt;If the line containing the district will always be the first for such a group, you can do this, using 2 lookup hash tables:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input municipality : $9. count pop rate;
cards;
Daejeon 1000 10000 10
A_city 300 2500 12
Daejeon 200 6000 3.3
B_city 500 1500 33.3
Busan 100 500 20
C_city 50 200 25
Busan 50 300 16.7
;

data districts;
input municipality :$9.;
datalines;
Daejeon
Busan
;

data want;
set have;
if _n_ = 1
then do;
  declare hash di (dataset:"districts");
  di.definekey("municipality");
  di.definedone();
  declare hash df ();
  df.definekey("municipality");
  df.definedone();
end;
retain district;
if di.check() = 0 and df.check() ne 0
then do;
  district = municipality;
  df.add();
  delete;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;di holds the reference which names can appear as districts, and df holds the reference if a certain name was already used for the district.&lt;/P&gt;</description>
      <pubDate>Mon, 04 May 2020 14:01:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Convert-sub-total-summary-rows-to-a-variable/m-p/645002#M78506</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-05-04T14:01:54Z</dc:date>
    </item>
  </channel>
</rss>

