<?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 Multiple columns in one column name in proc report in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705603#M216493</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have a table structure like&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ID Description 201201&amp;nbsp; 201202&amp;nbsp; 201203&amp;nbsp; 201204&amp;nbsp; 201205&amp;nbsp; 201301&amp;nbsp; 201302&amp;nbsp; 201303&amp;nbsp; 201304&amp;nbsp; 201305&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Now in proc report instead of defining multiple columns from &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;201201 to 201305&lt;/FONT&gt;&lt;/STRONG&gt;,&amp;nbsp; d&lt;/FONT&gt;&lt;FONT color="#000000"&gt;o we have a option to define all columns in one macro combined variable only?&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Dec 2020 07:33:25 GMT</pubDate>
    <dc:creator>harshpatel</dc:creator>
    <dc:date>2020-12-14T07:33:25Z</dc:date>
    <item>
      <title>Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705603#M216493</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have a table structure like&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ID Description 201201&amp;nbsp; 201202&amp;nbsp; 201203&amp;nbsp; 201204&amp;nbsp; 201205&amp;nbsp; 201301&amp;nbsp; 201302&amp;nbsp; 201303&amp;nbsp; 201304&amp;nbsp; 201305&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Now in proc report instead of defining multiple columns from &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;201201 to 201305&lt;/FONT&gt;&lt;/STRONG&gt;,&amp;nbsp; d&lt;/FONT&gt;&lt;FONT color="#000000"&gt;o we have a option to define all columns in one macro combined variable only?&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 07:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705603#M216493</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2020-12-14T07:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705604#M216494</link>
      <description>&lt;P&gt;"&lt;SPAN&gt;in one macro combined variable only". what do you mean by that?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 07:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705604#M216494</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-12-14T07:35:46Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705605#M216495</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;Basically my code should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc report data=test;&lt;/P&gt;
&lt;P&gt;column id description&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;here it should be one macro variable only from that multiple columns&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;define id;&lt;/P&gt;
&lt;P&gt;define description;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;define multiple columns&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 07:41:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705605#M216495</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2020-12-14T07:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705606#M216496</link>
      <description>&lt;P&gt;You should have a closer look at the usage of macro-variables. While you could add all the bad-named variable to macro-variable and use that in the column-statement, this approach won't work in the define-statement, because define accepts only one variable.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 07:52:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705606#M216496</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-12-14T07:52:14Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705607#M216497</link>
      <description>&lt;P&gt;If you have data like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options validvarname=any;
data test;
  retain ID Description '201201'n  '201202'n  '201203'n 0;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can get the list of variable names for the columns statement like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select cats("'",name,"'n") into :names separated by ' '
  from dictionary.columns where memname='TEST' and libname='WORK' and name like '2%';
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This assumes that the variables are actually named as you present it, an 201201, 201204 etc. are not column labels.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do a similar thing with the define statements (You will have to modify the definitions, I guess):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select catx(' ','define',cats("'",name,"'n"),'/analysis') into :defines separated by ';'
  from dictionary.columns where memname='TEST' and libname='WORK' and name like '2%';
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This should then be usable in a PROC REPORT:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=test;
  column id description &amp;amp;names;
  define id;
  define description;
  &amp;amp;defines;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to see the generated macro variables before running PROC REPORT, you can just %PUT the names variable:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put &amp;amp;names;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but the DEFINES variable needs to be quoted in a %PUT statement, because it contains semicolons:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%put %superq(defines);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 14 Dec 2020 08:10:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705607#M216497</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-12-14T08:10:32Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705611#M216500</link>
      <description>&lt;P&gt;Transpose to a long dataset, and use _NAME_ as an ACROSS column in PROC REPORT.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please post your PROC REPORT code, so we can show you how to do that.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 08:30:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705611#M216500</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-14T08:30:23Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705612#M216501</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;My dataset&amp;nbsp; looks like as below&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;ID Description 201201&amp;nbsp; 201202&amp;nbsp; 201203&amp;nbsp; 201204&amp;nbsp; 201205&amp;nbsp; 201301&amp;nbsp; 201302&amp;nbsp; 201303&amp;nbsp; 201304&amp;nbsp; 201305&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;Instead of defining multiple columns in define statement i want only one define statement for&lt;STRONG&gt; &lt;FONT color="#FF0000"&gt;201201 to 201305&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically my code should be&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc report data=test;&lt;/P&gt;
&lt;P&gt;column id description&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;here it should be one macro variable only from that multiple columns&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;define id;&lt;/P&gt;
&lt;P&gt;define description;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;define multiple columns&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 08:48:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705612#M216501</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2020-12-14T08:48:09Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705613#M216502</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Superb, it works for me&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 09:01:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705613#M216502</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2020-12-14T09:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705616#M216504</link>
      <description>&lt;P&gt;See this example:&lt;/P&gt;
&lt;P&gt;Data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id $ description $ '201201'n  '201202'n  '201203'n;
datalines;
A XXXX 1 2 3 
B YYYY 4 5 6
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Transpose:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=have out=long;
by id description;
var '20'n:;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You now have a structure that your data should have in the first place. See Maxim 19.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The report code is now extremely simple, and no complicated preparation of macro variables is needed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=long;
column id description _name_,col1;
define id / group;
define description / group;
define _name_ / across;
define col1 / analysis;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Bildschirmfoto 2020-12-14 um 10.11.36.png"&gt;&lt;img src="https://communities.sas.com/skins/images/70F8802BAA6255D55FBEC62A8226FB10/responsive_peak/images/image_not_found.png" alt="Bildschirmfoto 2020-12-14 um 10.11.36.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 09:12:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705616#M216504</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-14T09:12:30Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple columns in one column name in proc report</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705620#M216508</link>
      <description>&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;It is great, works for fine for me&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 09:19:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Multiple-columns-in-one-column-name-in-proc-report/m-p/705620#M216508</guid>
      <dc:creator>harshpatel</dc:creator>
      <dc:date>2020-12-14T09:19:21Z</dc:date>
    </item>
  </channel>
</rss>

