<?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: Nested column names - different sub column names per head column in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584967#M166731</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/287030"&gt;@EvelienV&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to build the following output per ID:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Aantekening 2019-08-28 142242.png" style="width: 527px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32076i16CAD4E5C41EC318/image-size/large?v=v2&amp;amp;px=999" role="button" title="Aantekening 2019-08-28 142242.png" alt="Aantekening 2019-08-28 142242.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I found this code in another thread:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=split5 nowd out=split6;
	column ('CGID' cgid) Theme1, theme2, count;
	define cgid / group '';
	define theme1 / across '';
	define theme2 / across '';
	define count / '';	
run; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but when I run this, I get all the subcolumn names in every head column (so Product experience gets 9 subcolumns, Value for money gets 9 subcolumns and the same goes for Content).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Herewith some sample code:&lt;/P&gt;
&lt;PRE&gt;data WORK.SPLIT5;
  infile datalines dsd truncover;
  input CGID:$7. Theme1:$150. Theme2:$150.;
  label CGID="CGID";
datalines;
2782189 Value for money Alignment with needs &amp;amp; expectations
2782189 Value for money Price transparancy
2782189 Product experience Speed
2782189 Product experience Search &amp;amp; filter options
2782189 Product experience Search results relevancy
2782189 Product experience Design
2782228 Content Quality of forms &amp;amp; tools (calculator, calendars)
2782228 Content Content quality
2782228 Value for money Price transparancy
2782231 Content Content quality
;;;;&lt;/PRE&gt;
&lt;P&gt;I'd like it to be as flexible as possible, as new 'Theme 2' options might come up every month...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know a fix for this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Evelien&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please check that your data steps create the data you need. The output I get from printing that data set is:&lt;/P&gt;
&lt;PRE&gt;From work.split5

Obs     CGID        Theme1      Theme2

  1    2782189
  2    2782189
  3    2782189
  4    2782189
  5    2782189
  6    2782189
  7    2782228    calendars)
  8    2782228
  9    2782228
 10    2782231


&lt;/PRE&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data WORK.SPLIT5;
  infile datalines dlm='|' dsd truncover;
  input CGID:$7. Theme1:$150. Theme2:$150.;
  label CGID="CGID";
datalines;
2782189|Value for money|Alignment with needs &amp;amp; expectations
2782189|Value for money|Price transparancy
2782189|Product experience|Speed
2782189|Product experience|Search &amp;amp; filter options
2782189|Product experience|Search results relevancy
2782189|Product experience|Design
2782228|Content|Quality of forms &amp;amp; tools (calculator, calendars)
2782228|Content|Content quality
2782228|Value for money|Price transparancy
2782231|Content|Content quality
;;;;&lt;/PRE&gt;
&lt;P&gt;For a basic count I think this comes pretty close to what you show.&lt;/P&gt;
&lt;PRE&gt;data WORK.SPLIT5;
  infile datalines dlm='|' dsd truncover;
  input CGID:$7. Theme1:$150. Theme2:$150.;
  label CGID="CGID";
datalines;
2782189|Value for money|Alignment with needs &amp;amp; expectations
2782189|Value for money|Price transparancy
2782189|Product experience|Speed
2782189|Product experience|Search &amp;amp; filter options
2782189|Product experience|Search results relevancy
2782189|Product experience|Design
2782228|Content|Quality of forms &amp;amp; tools (calculator, calendars)
2782228|Content|Content quality
2782228|Value for money|Price transparancy
2782231|Content|Content quality
;;;;

proc sql;
   create table work.temp as 
   select Distinct theme2 as start, theme1 as label,'Themes' as fmtname,
          'C' as type
   from work.split5
   ;
quit;

proc format library=work cntlin=work.temp;
run;
data work.rep;
   set work.split5;
   themeheader=theme2;
run;


proc tabulate data=work.rep;
   class theme2 themeheader cgid;
   format themeheader $themes.;
   tables cgid=' ',
          themeheader=' '*theme2=' '*n=' '
          /misstext='0'
   ;
run;&lt;/PRE&gt;
&lt;P&gt;But as soon as you throw other stuff in there I won't make any claims.&lt;/P&gt;
&lt;P&gt;I think part of the issue is the core way that proc report builds columns and without adding lots of variables and perhaps significant macro coding to account for "new values" this is as much as I can' come up with at this time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need compute blocks for things then you will need to provide more example data involving the other variables and what the output needs to be.&lt;/P&gt;</description>
    <pubDate>Thu, 29 Aug 2019 15:37:05 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-08-29T15:37:05Z</dc:date>
    <item>
      <title>Nested column names - different sub column names per head column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584531#M166510</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to build the following output per ID:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Aantekening 2019-08-28 142242.png" style="width: 527px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32076i16CAD4E5C41EC318/image-size/large?v=v2&amp;amp;px=999" role="button" title="Aantekening 2019-08-28 142242.png" alt="Aantekening 2019-08-28 142242.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I found this code in another thread:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=split5 nowd out=split6;
	column ('CGID' cgid) Theme1, theme2, count;
	define cgid / group '';
	define theme1 / across '';
	define theme2 / across '';
	define count / '';	
run; quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;but when I run this, I get all the subcolumn names in every head column (so Product experience gets 9 subcolumns, Value for money gets 9 subcolumns and the same goes for Content).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Herewith some sample code:&lt;/P&gt;&lt;PRE&gt;data WORK.SPLIT5;
  infile datalines dsd truncover;
  input CGID:$7. Theme1:$150. Theme2:$150.;
  label CGID="CGID";
datalines;
2782189 Value for money Alignment with needs &amp;amp; expectations
2782189 Value for money Price transparancy
2782189 Product experience Speed
2782189 Product experience Search &amp;amp; filter options
2782189 Product experience Search results relevancy
2782189 Product experience Design
2782228 Content Quality of forms &amp;amp; tools (calculator, calendars)
2782228 Content Content quality
2782228 Value for money Price transparancy
2782231 Content Content quality
;;;;&lt;/PRE&gt;&lt;P&gt;I'd like it to be as flexible as possible, as new 'Theme 2' options might come up every month...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know a fix for this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Evelien&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 06:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584531#M166510</guid>
      <dc:creator>EvelienV</dc:creator>
      <dc:date>2019-08-29T06:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Nested column names - different sub column names per head column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584637#M166548</link>
      <description>&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;Does this help?&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data work.split5;
length c1-c9 8;
call missing (of _all_);
label c1 = 'Speed'
      c2 = 'Search results relevancy'
      c3 = 'Search filter options'
      c4 = 'Design'
      c5 = 'Alignment with needs and expectation'
      c6 = 'Price value received'
      c7 = 'Price transparency'
      c8 = 'Quality of forms and tools'
      c9 = 'Content quality';
run;

ods _all_ close;

ods Excel file='C:\temp\tenp.xlsx' options(flow='header');
  proc report data=work.split5;
    column ('Product Experience' c1-c4) ('Value for Money' c5-c7) ('Content' c8-c9);
  run; quit;
ods Excel close;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;Vince DelGobbo&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="verdana,geneva"&gt;SAS R&amp;amp;D&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 16:11:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584637#M166548</guid>
      <dc:creator>Vince_SAS</dc:creator>
      <dc:date>2019-08-28T16:11:31Z</dc:date>
    </item>
    <item>
      <title>Re: Nested column names - different sub column names per head column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584678#M166568</link>
      <description>&lt;P&gt;Examples of what your current data looks like would go far to providing working example code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect that some form of reshaping your existing data is likely to be needed but the approach depends on what you have currently.&lt;/P&gt;
&lt;P&gt;Possibly assigning your Theme2 values to three other variables and using fixed column headings as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13635"&gt;@Vince_SAS&lt;/a&gt;&amp;nbsp;did for each of the single new variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 28 Aug 2019 17:40:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584678#M166568</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-28T17:40:15Z</dc:date>
    </item>
    <item>
      <title>Re: Nested column names - different sub column names per head column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584861#M166681</link>
      <description>&lt;P&gt;Thanks for the feedback, I've edited my original question and added some of my data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next to this, I'd like to keep the column names flexible if possible, since new ones might come up every month and I'd rather not have to add these manually to the list...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 06:29:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584861#M166681</guid>
      <dc:creator>EvelienV</dc:creator>
      <dc:date>2019-08-29T06:29:55Z</dc:date>
    </item>
    <item>
      <title>Re: Nested column names - different sub column names per head column</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584967#M166731</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/287030"&gt;@EvelienV&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm trying to build the following output per ID:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Aantekening 2019-08-28 142242.png" style="width: 527px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32076i16CAD4E5C41EC318/image-size/large?v=v2&amp;amp;px=999" role="button" title="Aantekening 2019-08-28 142242.png" alt="Aantekening 2019-08-28 142242.png" /&gt;&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;I found this code in another thread:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=split5 nowd out=split6;
	column ('CGID' cgid) Theme1, theme2, count;
	define cgid / group '';
	define theme1 / across '';
	define theme2 / across '';
	define count / '';	
run; quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but when I run this, I get all the subcolumn names in every head column (so Product experience gets 9 subcolumns, Value for money gets 9 subcolumns and the same goes for Content).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Herewith some sample code:&lt;/P&gt;
&lt;PRE&gt;data WORK.SPLIT5;
  infile datalines dsd truncover;
  input CGID:$7. Theme1:$150. Theme2:$150.;
  label CGID="CGID";
datalines;
2782189 Value for money Alignment with needs &amp;amp; expectations
2782189 Value for money Price transparancy
2782189 Product experience Speed
2782189 Product experience Search &amp;amp; filter options
2782189 Product experience Search results relevancy
2782189 Product experience Design
2782228 Content Quality of forms &amp;amp; tools (calculator, calendars)
2782228 Content Content quality
2782228 Value for money Price transparancy
2782231 Content Content quality
;;;;&lt;/PRE&gt;
&lt;P&gt;I'd like it to be as flexible as possible, as new 'Theme 2' options might come up every month...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does anyone know a fix for this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks in advance,&lt;/P&gt;
&lt;P&gt;Evelien&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Please check that your data steps create the data you need. The output I get from printing that data set is:&lt;/P&gt;
&lt;PRE&gt;From work.split5

Obs     CGID        Theme1      Theme2

  1    2782189
  2    2782189
  3    2782189
  4    2782189
  5    2782189
  6    2782189
  7    2782228    calendars)
  8    2782228
  9    2782228
 10    2782231


&lt;/PRE&gt;
&lt;P&gt;Consider:&lt;/P&gt;
&lt;PRE&gt;data WORK.SPLIT5;
  infile datalines dlm='|' dsd truncover;
  input CGID:$7. Theme1:$150. Theme2:$150.;
  label CGID="CGID";
datalines;
2782189|Value for money|Alignment with needs &amp;amp; expectations
2782189|Value for money|Price transparancy
2782189|Product experience|Speed
2782189|Product experience|Search &amp;amp; filter options
2782189|Product experience|Search results relevancy
2782189|Product experience|Design
2782228|Content|Quality of forms &amp;amp; tools (calculator, calendars)
2782228|Content|Content quality
2782228|Value for money|Price transparancy
2782231|Content|Content quality
;;;;&lt;/PRE&gt;
&lt;P&gt;For a basic count I think this comes pretty close to what you show.&lt;/P&gt;
&lt;PRE&gt;data WORK.SPLIT5;
  infile datalines dlm='|' dsd truncover;
  input CGID:$7. Theme1:$150. Theme2:$150.;
  label CGID="CGID";
datalines;
2782189|Value for money|Alignment with needs &amp;amp; expectations
2782189|Value for money|Price transparancy
2782189|Product experience|Speed
2782189|Product experience|Search &amp;amp; filter options
2782189|Product experience|Search results relevancy
2782189|Product experience|Design
2782228|Content|Quality of forms &amp;amp; tools (calculator, calendars)
2782228|Content|Content quality
2782228|Value for money|Price transparancy
2782231|Content|Content quality
;;;;

proc sql;
   create table work.temp as 
   select Distinct theme2 as start, theme1 as label,'Themes' as fmtname,
          'C' as type
   from work.split5
   ;
quit;

proc format library=work cntlin=work.temp;
run;
data work.rep;
   set work.split5;
   themeheader=theme2;
run;


proc tabulate data=work.rep;
   class theme2 themeheader cgid;
   format themeheader $themes.;
   tables cgid=' ',
          themeheader=' '*theme2=' '*n=' '
          /misstext='0'
   ;
run;&lt;/PRE&gt;
&lt;P&gt;But as soon as you throw other stuff in there I won't make any claims.&lt;/P&gt;
&lt;P&gt;I think part of the issue is the core way that proc report builds columns and without adding lots of variables and perhaps significant macro coding to account for "new values" this is as much as I can' come up with at this time.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need compute blocks for things then you will need to provide more example data involving the other variables and what the output needs to be.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Aug 2019 15:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Nested-column-names-different-sub-column-names-per-head-column/m-p/584967#M166731</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-29T15:37:05Z</dc:date>
    </item>
  </channel>
</rss>

