<?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: How do I combine multiple columns into one for output into Excel? in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309019#M17304</link>
    <description>&lt;P&gt;My mistake, I edited the post to reflect the difference.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Nov 2016 13:58:58 GMT</pubDate>
    <dc:creator>midnight_blue</dc:creator>
    <dc:date>2016-11-03T13:58:58Z</dc:date>
    <item>
      <title>How do I combine multiple columns into one for output into Excel?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309014#M17302</link>
      <description>&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Hello, using SAS 9.4, I am using a nested analysis from proc tabulate, output into a temp dataset (data were originally calculated with a nested sum function in proc tabulate; I then used a datastep to perform some other arithmetic functions), then using proc print to output the aritmetic calculations to Excel. &lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;For my final output, I would like to have some of the nested analysis levels within one column. Since I have to do this for three different top level analyses for multiple institutions, I am using a macro for the three different top levels. &lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;Let's say I have a column with a variable named group, and the value is Institution. Then, the data are nested within Institution. For example, the proc tabulate would calculate Institution &amp;gt; Sex &amp;gt; Age_Group.&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;In the resulting dataset from proc tabulate, the columns (variables) would have:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Group&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; | Sex&amp;nbsp;&amp;nbsp;&amp;nbsp; |&amp;nbsp;&amp;nbsp; Age_Group &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;----------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Institution | Male&amp;nbsp;&amp;nbsp; | &amp;nbsp; Age 18-64 &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Institution | Female | &amp;nbsp; Age 65-74&amp;nbsp; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;The values for Sex and Age_Group apply a character format to display as male, age 18-64, etc. These are defined in the datastep after the output dataset from proc tabulate. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;What I would like to see is (in one column from the output: &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Group&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;-----------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Institution&amp;nbsp;&amp;nbsp; Male&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age 18-64 |&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;What I am currently getting is an output like this: &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Group&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; |&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;-----------------------------------&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Institution&amp;nbsp;&amp;nbsp; Sex &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Age_Group |&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;My code in the data step is currently set up like this: &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Group = "Institution &amp;amp;lvl1. &amp;amp;lvl2.";&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Where "Institution" does not change (it will always preceed with Institution) and &amp;amp;lvl1. &amp;amp;lvl2. are the macro variables for Sex and Age_Group (these change depending on the analysis (can change to things like race, ethnicity, etc. but the basic idea is the same). &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Then I proc print the resulting data from the data step (along with other variabless) into excel using the ods tagsets.excelxp&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;So basically: proc tabulate &amp;gt; output data &amp;gt; data step manipulation &amp;gt; ods tagsets excelxp proc print after the dataset data step manipulation &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Any and all help appreciated. &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;Thank you!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 13:58:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309014#M17302</guid>
      <dc:creator>midnight_blue</dc:creator>
      <dc:date>2016-11-03T13:58:30Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple columns into one for output into Excel?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309016#M17303</link>
      <description>&lt;P&gt;Can't see the difference between what you have and want right now.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 13:57:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309016#M17303</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-11-03T13:57:17Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple columns into one for output into Excel?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309019#M17304</link>
      <description>&lt;P&gt;My mistake, I edited the post to reflect the difference.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 13:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309019#M17304</guid>
      <dc:creator>midnight_blue</dc:creator>
      <dc:date>2016-11-03T13:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple columns into one for output into Excel?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309021#M17305</link>
      <description>&lt;P&gt;So what is the actual question? &amp;nbsp;Post test data (form of a datastep), and required output. &amp;nbsp;Maybe also show your code as I don't see the need for macro here?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 14:00:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309021#M17305</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-11-03T14:00:45Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple columns into one for output into Excel?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309048#M17307</link>
      <description>&lt;P&gt;Why Excel? If you are putting what are actually multiple data fields into a single cell it seem highly unlikely that any one needs the Excel tools to further manipulate the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want SAS to write to column then you will need to create a new variable to hold the combined value.&lt;/P&gt;
&lt;P&gt;something like&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; length longvalue $ 35;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; longvalue = catx(' ',group,sex,age);&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;You may have to fiddle with exactly how you want to combine the values, whether Put(variable,format.) may be needed instead of just the variable and such.Note that if you display the result with proportional fonts you will spend a lot time trying to get things to line up and I'm not going to go there for Excel output.&lt;/P&gt;
&lt;P&gt;Then have your proc print only display the desired variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 16:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309048#M17307</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-11-03T16:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: How do I combine multiple columns into one for output into Excel?</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309050#M17308</link>
      <description>&lt;P&gt;Thank you, I will have to try this and report back.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Nov 2016 14:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/How-do-I-combine-multiple-columns-into-one-for-output-into-Excel/m-p/309050#M17308</guid>
      <dc:creator>midnight_blue</dc:creator>
      <dc:date>2016-11-03T14:49:31Z</dc:date>
    </item>
  </channel>
</rss>

