<?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: Dynamic columns in Proc Report in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Dynamic-columns-in-Proc-Report/m-p/474420#M71092</link>
    <description>&lt;P&gt;Several ways.&amp;nbsp; First one is to have the variables in the right order in your dataset, then you don't need to do anything other than:&lt;/P&gt;
&lt;PRE&gt;columns _all_;&lt;/PRE&gt;
&lt;P&gt;And they will come out in the dataset order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second is to create a list of variables from metadata:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select distinct name 
  into :vlist separated by " "
  from dictionary.columns
  where libname="WORK" 
    and memname="SITE_PERF_TIME" 
    and char(name,1)="Y";
quit;

proc report...
  columns consented ... current &amp;amp;vlist.;
...
run;&lt;/PRE&gt;
&lt;P&gt;Alternatively you could have the year and quarter as observations, then use an across statement to transpose them up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jun 2018 13:13:33 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2018-06-29T13:13:33Z</dc:date>
    <item>
      <title>Dynamic columns in Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamic-columns-in-Proc-Report/m-p/474417#M71091</link>
      <description>&lt;P&gt;I have a performance report where the columns are generated by quarter. I want to know if there is a way to add in all the columns and leverage some kind of "If exists" option to prevent errors when running the report.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a code snippet of what I mean.&amp;nbsp; I want to add in all of the quarters so they appear in the correct order. If they don't exist yet, the report will error out. How do I handle this dynamic column issue?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc report data=site_perf_time missing split='?' spanrows;

columns  consented enrolled metric_name Current Y2017Q4 Y2018Q1 Y2018Q2 Y2018Q3 Y2018Q4 ; 
    
     define consented/ group "Consented"; 
     define enrolled/ group "Enrolled"; 
     define metric_name/ order "Metric"; 
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 13:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamic-columns-in-Proc-Report/m-p/474417#M71091</guid>
      <dc:creator>tanya_henderson</dc:creator>
      <dc:date>2018-06-29T13:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic columns in Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamic-columns-in-Proc-Report/m-p/474420#M71092</link>
      <description>&lt;P&gt;Several ways.&amp;nbsp; First one is to have the variables in the right order in your dataset, then you don't need to do anything other than:&lt;/P&gt;
&lt;PRE&gt;columns _all_;&lt;/PRE&gt;
&lt;P&gt;And they will come out in the dataset order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The second is to create a list of variables from metadata:&lt;/P&gt;
&lt;PRE&gt;proc sql noprint;
  select distinct name 
  into :vlist separated by " "
  from dictionary.columns
  where libname="WORK" 
    and memname="SITE_PERF_TIME" 
    and char(name,1)="Y";
quit;

proc report...
  columns consented ... current &amp;amp;vlist.;
...
run;&lt;/PRE&gt;
&lt;P&gt;Alternatively you could have the year and quarter as observations, then use an across statement to transpose them up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 13:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamic-columns-in-Proc-Report/m-p/474420#M71092</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-06-29T13:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic columns in Proc Report</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Dynamic-columns-in-Proc-Report/m-p/474425#M71095</link>
      <description>&lt;P&gt;Quick and easy tricks to try ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This might work, or it might not give you enough control over the order:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;columns&lt;/SPAN&gt;  consented enrolled metric_name Current Y2017Q4 Y2018Q:&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This might work, or might give you an error (one way to find out):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token keyword"&gt;columns&lt;/SPAN&gt;  consented enrolled metric_name Current Y2017Q4 Y2018Q1: Y2018Q2: Y2018Q3: Y2018Q4: &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jun 2018 13:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Dynamic-columns-in-Proc-Report/m-p/474425#M71095</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-06-29T13:20:04Z</dc:date>
    </item>
  </channel>
</rss>

