<?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: Grouping variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/448020#M112644</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
input n text $;
cards;
1	ab	
2	abc	
3	ad	
4	abc	
5	hi	
;
run;

data table2;
infile cards truncover;
input group1 $ group2 $ group3 $ ;
cards;
ab ad hi
abc
;
run;

data want;
if _n_=1 then do;
if 0 then do;set table1;set table2;end;
dcl hash H (dataset:'table1',multidata:'y') ;
   h.definekey  ('text') ;
   h.definedata ('text','n') ;
   h.definedone () ;
dcl hash H1 (dataset:'table2') ;
   h1.definekey  ('group1', 'group2','group3') ;
   h1.definedone () ;
declare hiter iter('h1');
   end;
array grp(*) group:;
rc = iter.first();
do while (rc = 0);
	do _n_=1 to dim(grp);
 		do while(h.do_over(key:grp(_n_)) eq 0);
  			Column_you_would_like=vname(grp(_n_));
  			output;
		end;
	
	end;
rc = iter.next();
end;
stop;
drop rc group:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 23 Mar 2018 01:17:21 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2018-03-23T01:17:21Z</dc:date>
    <item>
      <title>Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447779#M112636</link>
      <description>&lt;P&gt;Hi SAS Experts&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to group a variable&amp;nbsp;that contains a&amp;nbsp;wide&amp;nbsp;range of "text". I&amp;nbsp;have the grouping of the variables in another dataset&amp;nbsp;where the different versions of the text&amp;nbsp;that needs to&amp;nbsp;be grouped together is&amp;nbsp;listed in different variables. How can I do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;I'm using Base SAS 9.4&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an example of the data I have and that I would like to recode. I the real world there are 1000s of lines.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;n&lt;/TD&gt;&lt;TD&gt;text&lt;/TD&gt;&lt;TD&gt;Column i would like&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;ab&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;ad&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;hi&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is&amp;nbsp;an example of the other dataset that I have which should define the recoding.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ab&lt;/TD&gt;&lt;TD&gt;ad&lt;/TD&gt;&lt;TD&gt;hi&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;abc&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope you can help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solvej&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 13:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447779#M112636</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-03-22T13:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447782#M112637</link>
      <description>&lt;P&gt;So does the next row with "Column I would like" equal to 2 go beside "abc" in your result?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This seems to me like an odd algorithm...I think something may be missing. How do your "column 2 and 3" values match up to the correct "column 1" values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 14:07:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447782#M112637</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2018-03-22T14:07:29Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447784#M112638</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi Tom&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;There is no relationship between the different columns in the second dataset. Basically it is just&amp;nbsp;a three different lists of text bits&amp;nbsp;where the header is the number I would like to implement in data set 1.&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 hope this makes sense, &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;Solvej&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 14:13:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447784#M112638</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-03-22T14:13:34Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447791#M112639</link>
      <description>&lt;P&gt;&lt;BR /&gt;proc transpose data=test out=test2;&lt;BR /&gt;id col;&lt;BR /&gt;var text;&lt;BR /&gt;by n;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then edit the data as you like.&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 14:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447791#M112639</guid>
      <dc:creator>anandgupta22</dc:creator>
      <dc:date>2018-03-22T14:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447794#M112640</link>
      <description>&lt;P&gt;Dear anandgupta22&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your answer but I dont think that is sufficient. I want to use the information from&amp;nbsp;dataset 2 to recode in data 1. I the real World both dataset 1 and 2 are very complicated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Solvej&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 14:30:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447794#M112640</guid>
      <dc:creator>Solvej</dc:creator>
      <dc:date>2018-03-22T14:30:42Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447800#M112641</link>
      <description>&lt;P&gt;proc transpose data=test out=test2 name=column;&lt;BR /&gt;var 1-3;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 14:38:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447800#M112641</guid>
      <dc:creator>anandgupta22</dc:creator>
      <dc:date>2018-03-22T14:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447861#M112642</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/108044"&gt;@Solvej&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Dear anandgupta22&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for your answer but I dont think that is sufficient. I want to use the information from&amp;nbsp;dataset 2 to recode in data 1. I the real World both dataset 1 and 2 are very complicated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Solvej&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Is your example representative of your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the answer from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/200579"&gt;@anandgupta22&lt;/a&gt;&amp;nbsp;is correct though. Transpose Table 2 and then a left join/hash/format should be all you need. Is there some reason you think it's more complex than that?&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 17:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447861#M112642</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-22T17:24:14Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447865#M112643</link>
      <description>&lt;P&gt;This works exactly as you have described.&lt;/P&gt;
&lt;P&gt;If it doesn't work on your data, please explain in detail how it does not work and include sample records that illustrate how.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
input n text $;
cards;
1	ab	
2	abc	
3	ad	
4	abc	
5	hi	
;
run;

data table2;
infile cards truncover;
input group1 $ group2 $ group3 $ ;
cards;
ab ad hi
abc
;
run;

data group_fmt_data;
set table2;
array g(3) $ group1-group3;
type='C';
fmtname='group_fmt';
do i=1 to dim(g);
Label = i;
Start = g(i);
if not missing(Start) then output;
end;

keep type fmtname label start;
run;

proc format cntlin=group_fmt_data;
run;
data want;
set table1;
group = put(text, group_fmt.);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 22 Mar 2018 17:37:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/447865#M112643</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-22T17:37:49Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/448020#M112644</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
input n text $;
cards;
1	ab	
2	abc	
3	ad	
4	abc	
5	hi	
;
run;

data table2;
infile cards truncover;
input group1 $ group2 $ group3 $ ;
cards;
ab ad hi
abc
;
run;

data want;
if _n_=1 then do;
if 0 then do;set table1;set table2;end;
dcl hash H (dataset:'table1',multidata:'y') ;
   h.definekey  ('text') ;
   h.definedata ('text','n') ;
   h.definedone () ;
dcl hash H1 (dataset:'table2') ;
   h1.definekey  ('group1', 'group2','group3') ;
   h1.definedone () ;
declare hiter iter('h1');
   end;
array grp(*) group:;
rc = iter.first();
do while (rc = 0);
	do _n_=1 to dim(grp);
 		do while(h.do_over(key:grp(_n_)) eq 0);
  			Column_you_would_like=vname(grp(_n_));
  			output;
		end;
	
	end;
rc = iter.next();
end;
stop;
drop rc group:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Mar 2018 01:17:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/448020#M112644</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-23T01:17:21Z</dc:date>
    </item>
    <item>
      <title>Re: Grouping variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/448023#M112645</link>
      <description>&lt;P&gt;Further simplified and easy:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data table1;
input n text $;
cards;
1	ab	
2	abc	
3	ad	
4	abc	
5	hi	
;
run;

data table2;
infile cards truncover;
input group1 $ group2 $ group3 $ ;
cards;
ab ad hi
abc
;
run;

data want;
if _n_=1 then do;
if 0 then set table2;
dcl hash H1 (dataset:'table2') ;
   h1.definekey  ('group1', 'group2','group3') ;
   h1.definedone () ;
declare hiter iter('h1');
   end;
set table1;
array grp(*) group:;
rc = iter.first();
do while (rc = 0);
	do _n_=1 to dim(grp);
 	if grp(_n_)=text then do; Column_you_would_like=vname(grp(_n_));output;return;end;
  	end;
rc = iter.next();
end;
stop;
drop rc group:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 23 Mar 2018 01:30:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Grouping-variables/m-p/448023#M112645</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-23T01:30:39Z</dc:date>
    </item>
  </channel>
</rss>

