<?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: Create new tables based on unique value combinations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/890073#M351683</link>
    <description>&lt;P&gt;This code makes as many datasets (named DATASET_01, DATASET_02, etc.) as there are unique combinations of comment and description.&amp;nbsp; Each dataset will have a dataset label describing the values taken by comment and description:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines dlm=',';
   input Member Description:$25. Comment :$25.;
datalines;
1,given 2 doses,Ingested doses
2,given 3 doses,Did not ingest doses
4,given 3 doses,Did not ingest doses
6,given 2 doses,Did not ingest doses
;

data _null_;
  if 0 then set have;
  declare hash h (dataset:'have',multidata:'Y',ordered:'a');      
    h.definekey('description','comment');
    h.definedata(all:'Y');
    h.definedone();
  declare hiter hi ('h');

  do until (hi.next()^=0);
    if description^=lag(description) or comment^=lag(comment) then do;
      t=sum(t,1);
      h.output(dataset:catx(' ',cats('dataset_',put(t,z2.))
                           ,cats('(label="COMMENT=',comment)
                           ,'and'
                           ,cats('DESCRIPTION=',description,'"')
                           ,'where=(comment=',quote(comment)
                           ,'and description=',quote(description)
                           ,")")
              );
    end;
  end;
  stop;
run;&lt;/PRE&gt;</description>
    <pubDate>Sat, 19 Aug 2023 22:28:06 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2023-08-19T22:28:06Z</dc:date>
    <item>
      <title>Create new tables based on unique value combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889927#M351608</link>
      <description>&lt;P&gt;Hello,&amp;nbsp; I'm trying to create a table for each new value combination across 2 variables.&amp;nbsp; Here is the example data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Member&amp;nbsp; Description&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Comment&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;given 2 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Ingested doses&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 3 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 3 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 2 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So ideally 3 data tables would be output based on unique combinations of description and comment.&amp;nbsp; Output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 1:&lt;/P&gt;&lt;P&gt;Member&amp;nbsp; Description&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Comment&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;given 2 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Ingested doses&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 2:&lt;/P&gt;&lt;P&gt;Member&amp;nbsp; Description&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Comment&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 3 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 3 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Table 3:&lt;/P&gt;&lt;P&gt;Member&amp;nbsp; Description&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Comment&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 2 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 16:33:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889927#M351608</guid>
      <dc:creator>jmmedina252</dc:creator>
      <dc:date>2023-08-18T16:33:21Z</dc:date>
    </item>
    <item>
      <title>Re: Create new tables based on unique value combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889928#M351609</link>
      <description>Why do you want new tables?</description>
      <pubDate>Fri, 18 Aug 2023 16:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889928#M351609</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-08-18T16:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Create new tables based on unique value combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889956#M351623</link>
      <description>Are you certain that all 3 tables use the same spelling and same capitalization?  Should different variations be lumped together?</description>
      <pubDate>Fri, 18 Aug 2023 17:51:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889956#M351623</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2023-08-18T17:51:51Z</dc:date>
    </item>
    <item>
      <title>Re: Create new tables based on unique value combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889961#M351627</link>
      <description>&lt;UL&gt;
&lt;LI&gt;Create a grouping variable then split on the grouping variable - but I don't recommend doing that unless you have a very good reason.&lt;/LI&gt;
&lt;/UL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by description comment;
run;

data grouped;
set have;
by description comment;
retain group 0;
if first.comment then group+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/439355"&gt;@jmmedina252&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&amp;nbsp; I'm trying to create a table for each new value combination across 2 variables.&amp;nbsp; Here is the example data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Member&amp;nbsp; Description&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Comment&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;given 2 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Ingested doses&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 3 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 3 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;
&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 2 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So ideally 3 data tables would be output based on unique combinations of description and comment.&amp;nbsp; Output:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table 1:&lt;/P&gt;
&lt;P&gt;Member&amp;nbsp; Description&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Comment&lt;/P&gt;
&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;given 2 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Ingested doses&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table 2:&lt;/P&gt;
&lt;P&gt;Member&amp;nbsp; Description&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Comment&lt;/P&gt;
&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 3 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;
&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 3 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table 3:&lt;/P&gt;
&lt;P&gt;Member&amp;nbsp; Description&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Comment&lt;/P&gt;
&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; given 2 doses&amp;nbsp; &amp;nbsp; &amp;nbsp; Did not ingest doses&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Aug 2023 17:59:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889961#M351627</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-08-18T17:59:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create new tables based on unique value combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889964#M351629</link>
      <description>&lt;P&gt;Tell use how we KNOW something is a "new value".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the advantage of creating multiple tables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can get similar output such as from Proc Print with this.&lt;/P&gt;
&lt;P&gt;Note use of a data step to provide working data (Hint Hint Hint)&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines dlm=',';
   input Member Description:$25. Comment :$25.;
datalines;
1,given 2 doses,Ingested doses
2,given 3 doses,Did not ingest doses
4,given 3 doses,Did not ingest doses
6,given 2 doses,Did not ingest doses
;

proc sort data=have;
   by description comment;
run;

options nobyline;
proc print data=have noobs;
   by description comment;
   var member description comment;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 18 Aug 2023 18:07:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/889964#M351629</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-18T18:07:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create new tables based on unique value combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/890041#M351667</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   infile datalines dlm=',';
   input Member Description:$25. Comment :$25.;
datalines;
1,given 2 doses,Ingested doses
2,given 3 doses,Did not ingest doses
4,given 3 doses,Did not ingest doses
6,given 2 doses,Did not ingest doses
;

data have;
 set have;
 id=catx('|',Description,Comment);
run;
proc freq data=have noprint;
table id/out=id nopercent;
run;
data _null_;
 set id;
 call execute(catt('data table_',_n_,'(drop=id);set have;if id="',id,'";run;'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Aug 2023 10:00:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/890041#M351667</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2023-08-19T10:00:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create new tables based on unique value combinations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/890073#M351683</link>
      <description>&lt;P&gt;This code makes as many datasets (named DATASET_01, DATASET_02, etc.) as there are unique combinations of comment and description.&amp;nbsp; Each dataset will have a dataset label describing the values taken by comment and description:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines dlm=',';
   input Member Description:$25. Comment :$25.;
datalines;
1,given 2 doses,Ingested doses
2,given 3 doses,Did not ingest doses
4,given 3 doses,Did not ingest doses
6,given 2 doses,Did not ingest doses
;

data _null_;
  if 0 then set have;
  declare hash h (dataset:'have',multidata:'Y',ordered:'a');      
    h.definekey('description','comment');
    h.definedata(all:'Y');
    h.definedone();
  declare hiter hi ('h');

  do until (hi.next()^=0);
    if description^=lag(description) or comment^=lag(comment) then do;
      t=sum(t,1);
      h.output(dataset:catx(' ',cats('dataset_',put(t,z2.))
                           ,cats('(label="COMMENT=',comment)
                           ,'and'
                           ,cats('DESCRIPTION=',description,'"')
                           ,'where=(comment=',quote(comment)
                           ,'and description=',quote(description)
                           ,")")
              );
    end;
  end;
  stop;
run;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 Aug 2023 22:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-tables-based-on-unique-value-combinations/m-p/890073#M351683</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2023-08-19T22:28:06Z</dc:date>
    </item>
  </channel>
</rss>

