<?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: group the values ​​of a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/701214#M214702</link>
    <description>&lt;PRE&gt;data orig;
    input id bank;
    cards;
1   1025  
1   4567  
1   1025  
1   3567
2   1025
2   4625
;
run;

proc sort data=orig;
    by id;
run;

data orig2;
do until(last.id);
   set orig; 
   by id;
   length all_bank $ 200;
   if not findw(all_bank,strip(bank),' ') then all_bank=catx(' ',all_bank,bank);
end;
do until(last.id);
   set orig; 
   by id;
   other_bank=translate(compbl(strip(prxchange(cats('s/\b',bank,'\b//'),-1,all_bank))),';',' ');
   output;
end;
drop all_bank;
run;

&lt;/PRE&gt;</description>
    <pubDate>Tue, 24 Nov 2020 13:32:08 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2020-11-24T13:32:08Z</dc:date>
    <item>
      <title>group the values ​​of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700898#M214555</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I have an issue. I would like to group the values of a variable.&lt;/P&gt;&lt;P&gt;For example, I have this :&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp; bank&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 1025&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 4567&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 1025&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 3567&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 1025&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 4625&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I would like to have :&lt;/P&gt;&lt;P&gt;id&amp;nbsp;&amp;nbsp; bank&amp;nbsp;&amp;nbsp; other_bank&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 1025&amp;nbsp;&amp;nbsp; 4567; 3567&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 4567&amp;nbsp;&amp;nbsp; 1025;3567&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 1025&amp;nbsp;&amp;nbsp; 4567;3576&lt;/P&gt;&lt;P&gt;1&amp;nbsp;&amp;nbsp; 3567&amp;nbsp;&amp;nbsp; 1025;4567&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 1025&amp;nbsp;&amp;nbsp; 4625&lt;/P&gt;&lt;P&gt;2&amp;nbsp;&amp;nbsp; 4625&amp;nbsp;&amp;nbsp; 1025&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried this but it's not enough what I want:&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;data orig;
    input id bank;
    cards;
1   1025  
1   4567  
1   1025  
1   3567
2   1025
2   4625
;
run;

proc sort data=orig;
    by id;
run;

data orig2;
   set orig; 
   by id;
   length other_bank $ 30;
   retain other_bank;

   if first.id then other_bank=bank;
   else other_bank=catx(';',other_bank,bank); 

run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 13:33:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700898#M214555</guid>
      <dc:creator>unifly</dc:creator>
      <dc:date>2020-11-23T13:33:56Z</dc:date>
    </item>
    <item>
      <title>Re: group the values ​​of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700907#M214557</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop=b);
   dcl hash h (dataset : 'have(rename=bank=b)', multidata : 'Y');
   h.definekey('id');
   h.definedata('b');
   h.definedone();

   set have;
   length other_bank b $200;
   call missing(other_bank);

   do while (h.do_over() = 0);
      if bank ne b and indexw(other_bank, strip(b), ' ;') = 0 
         then other_bank = catx(';', other_bank, strip(b));
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;id  bank  other_bank 
1   1025  4567;3567 
1   4567  1025;3567 
1   1025  4567;3567 
1   3567  1025;4567
2   1025  4625 
2   4625  1025 
&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Nov 2020 14:21:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700907#M214557</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-23T14:21:04Z</dc:date>
    </item>
    <item>
      <title>Re: group the values ​​of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700908#M214558</link>
      <description>&lt;P&gt;Please explain the logic that creates the output data set from the input data set.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 14:11:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700908#M214558</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-11-23T14:11:43Z</dc:date>
    </item>
    <item>
      <title>Re: group the values ​​of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700916#M214561</link>
      <description>thanks it's exactly what I want, but it doesn't work when I run it. Does your set "have" is exactly the same than my set "orig" ?</description>
      <pubDate>Mon, 23 Nov 2020 14:30:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700916#M214561</guid>
      <dc:creator>unifly</dc:creator>
      <dc:date>2020-11-23T14:30:56Z</dc:date>
    </item>
    <item>
      <title>Re: group the values ​​of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700919#M214562</link>
      <description>because I have the Following errors :&lt;BR /&gt;ERROR: Type mismatch for data variable b at ligne 46 colonne 4.&lt;BR /&gt;ERROR: Hash data set load failed at ligne 46 colonne 4.&lt;BR /&gt;ERROR: DATA STEP Component Object failure. Aborted during the EXECUTION phase.</description>
      <pubDate>Mon, 23 Nov 2020 14:39:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700919#M214562</guid>
      <dc:creator>unifly</dc:creator>
      <dc:date>2020-11-23T14:39:01Z</dc:date>
    </item>
    <item>
      <title>Re: group the values ​​of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700927#M214566</link>
      <description>&lt;P&gt;Sorry, did not realize your variables were numeric. This should do it. Let me know if it works..&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data orig;
    input id bank;
    cards;
1   1025
1   4567
1   1025
1   3567
2   1025
2   4625
;
run;

data want(drop=b);
   if _N_ = 1 then do;
      dcl hash h (dataset : 'orig(rename=bank=b)', multidata : 'Y');
      h.definekey('id');
      h.definedata('b');
      h.definedone();
   end;

   set orig;
   length other_bank $200;
   call missing(other_bank);

   do while (h.do_over() = 0);
      if bank ne b and indexw(other_bank, strip(put(b, 8.)), ' ;') = 0 
         then other_bank = catx(';', other_bank, strip(put(b, 8.)));
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Nov 2020 15:10:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700927#M214566</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-23T15:10:00Z</dc:date>
    </item>
    <item>
      <title>Re: group the values ​​of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700932#M214571</link>
      <description>awesome ! thanks a lot&lt;BR /&gt;</description>
      <pubDate>Mon, 23 Nov 2020 15:29:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700932#M214571</guid>
      <dc:creator>unifly</dc:creator>
      <dc:date>2020-11-23T15:29:30Z</dc:date>
    </item>
    <item>
      <title>Re: group the values ​​of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700971#M214594</link>
      <description>&lt;P&gt;Anytime.&lt;/P&gt;</description>
      <pubDate>Mon, 23 Nov 2020 16:46:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/700971#M214594</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-11-23T16:46:04Z</dc:date>
    </item>
    <item>
      <title>Re: group the values ​​of a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/701214#M214702</link>
      <description>&lt;PRE&gt;data orig;
    input id bank;
    cards;
1   1025  
1   4567  
1   1025  
1   3567
2   1025
2   4625
;
run;

proc sort data=orig;
    by id;
run;

data orig2;
do until(last.id);
   set orig; 
   by id;
   length all_bank $ 200;
   if not findw(all_bank,strip(bank),' ') then all_bank=catx(' ',all_bank,bank);
end;
do until(last.id);
   set orig; 
   by id;
   other_bank=translate(compbl(strip(prxchange(cats('s/\b',bank,'\b//'),-1,all_bank))),';',' ');
   output;
end;
drop all_bank;
run;

&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Nov 2020 13:32:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/group-the-values-of-a-variable/m-p/701214#M214702</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-11-24T13:32:08Z</dc:date>
    </item>
  </channel>
</rss>

