<?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 Dynamically create columns in PROC REPORT in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-create-columns-in-PROC-REPORT/m-p/765037#M242296</link>
    <description>&lt;P&gt;I am trying to use a string that is saved in a metadata file in order to dynamically create headers for PROC REPORT. I use this code snippet to create a small data set with all of the words to be used as column headers.&lt;/P&gt;&lt;PRE&gt;data defines;
	length word $100;
	drop string;
	DO UNTIL(word="");
		count+1;
		word=scan("&amp;amp;xcols", count, ".");
		output;
		end;
run;&lt;/PRE&gt;&lt;P&gt;Next I run this code to get the min and max number to iterate through for the headers.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL noprint;
	SELECT min(count), max(count)
	INTO :xmin, :xmax
	FROM defines;
quit;&lt;/PRE&gt;&lt;P&gt;Then this is where I am getting stuck. I need to know how to define the columns correctly as well as display the correct column header. For example the first column header would be the first observation in the defines data set, second header would be the second obs in the data set and so on. I have also included the dummy data set creation here.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data dummy;&lt;BR /&gt;length F1-F10 $100;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc report data=dummy nowd

	COLUMNS F1-F10;

	%DO r=&amp;amp;xmin %TO &amp;amp;xmax;
		DEFINE VVALUEX("F"||&amp;amp;r) DISPLAY "TEST"; 
	%END;

run; &lt;/PRE&gt;&lt;P&gt;I am open to a more efficient solution to this problem as well. Any feedback helps! Thanks&lt;/P&gt;</description>
    <pubDate>Tue, 31 Aug 2021 12:42:17 GMT</pubDate>
    <dc:creator>rbick</dc:creator>
    <dc:date>2021-08-31T12:42:17Z</dc:date>
    <item>
      <title>Dynamically create columns in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-create-columns-in-PROC-REPORT/m-p/765037#M242296</link>
      <description>&lt;P&gt;I am trying to use a string that is saved in a metadata file in order to dynamically create headers for PROC REPORT. I use this code snippet to create a small data set with all of the words to be used as column headers.&lt;/P&gt;&lt;PRE&gt;data defines;
	length word $100;
	drop string;
	DO UNTIL(word="");
		count+1;
		word=scan("&amp;amp;xcols", count, ".");
		output;
		end;
run;&lt;/PRE&gt;&lt;P&gt;Next I run this code to get the min and max number to iterate through for the headers.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL noprint;
	SELECT min(count), max(count)
	INTO :xmin, :xmax
	FROM defines;
quit;&lt;/PRE&gt;&lt;P&gt;Then this is where I am getting stuck. I need to know how to define the columns correctly as well as display the correct column header. For example the first column header would be the first observation in the defines data set, second header would be the second obs in the data set and so on. I have also included the dummy data set creation here.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data dummy;&lt;BR /&gt;length F1-F10 $100;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc report data=dummy nowd

	COLUMNS F1-F10;

	%DO r=&amp;amp;xmin %TO &amp;amp;xmax;
		DEFINE VVALUEX("F"||&amp;amp;r) DISPLAY "TEST"; 
	%END;

run; &lt;/PRE&gt;&lt;P&gt;I am open to a more efficient solution to this problem as well. Any feedback helps! Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 12:42:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-create-columns-in-PROC-REPORT/m-p/765037#M242296</guid>
      <dc:creator>rbick</dc:creator>
      <dc:date>2021-08-31T12:42:17Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamically create column LABELs in PROC REPORT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dynamically-create-columns-in-PROC-REPORT/m-p/765065#M242311</link>
      <description>&lt;P&gt;Example using phony data in data set HAVE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    set sashelp.class(rename=(age=f1 height=f2 weight=f3));
run;

%let xcols=Age.Height.Weight;
%macro report;
proc report data=have;
    columns f1-f3;
    %do i=1 %to %sysfunc(countw(&amp;amp;xcols,.));
        %let thiscol=%scan(&amp;amp;xcols,&amp;amp;i,.);
        define f&amp;amp;i/display "&amp;amp;thiscol";
    %end;
run;
%mend;
%report&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 14:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dynamically-create-columns-in-PROC-REPORT/m-p/765065#M242311</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-31T14:24:26Z</dc:date>
    </item>
  </channel>
</rss>

