<?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: Working with metadata, I have a list of columns I want to dynamically place in proc sql select? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Working-with-metadata-I-have-a-list-of-columns-I-want-to/m-p/765079#M242316</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43996"&gt;@kjohnsonm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;sas 9.4 for Windoes&lt;BR /&gt;Have data set list like so:&lt;BR /&gt;column_item_1&lt;/P&gt;
&lt;P&gt;column_item_2&lt;/P&gt;
&lt;P&gt;column_item_3&lt;/P&gt;
&lt;P&gt;column_item_4&lt;/P&gt;
&lt;P&gt;column_item_...&lt;/P&gt;
&lt;P&gt;column_item_n&lt;BR /&gt;&lt;BR /&gt;want:&lt;BR /&gt;%put &amp;amp;my_var.;&lt;BR /&gt;column_item_1, column_item_2, column_item_3, column_item_4, column_item_..., column_item_n&lt;BR /&gt;&lt;BR /&gt;Please note as needed 'proc sql' needs commas between columns but not after the last column, &lt;BR /&gt;The column count can change&lt;BR /&gt;Can get a count on the total length of the strings individual strings, and as a whole&lt;BR /&gt;Can get the total number of column_items&lt;BR /&gt;but they can and do change from run to run depending on table input.&lt;BR /&gt;TIA.&amp;nbsp;&amp;nbsp; -KJ&lt;BR /&gt;I have been trying with proc transpose to go from long to wide then use one of the cat-s but have not figure out the trick yet.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It certainly helps to provide such information as the name of your variable holding the values you want and the name of the data set.&lt;/P&gt;
&lt;P&gt;See below for an example that creates a data set similar to what you describe (hint: best practice to show data), and creates a macro variable as you request:&lt;/P&gt;
&lt;PRE&gt;data have;
   input name :$13.;
datalines;
column_item_1
column_item_2
column_item_3
column_item_4
column_item_5
column_item_n
;

proc sql noprint;
   select name into :mvar separated by ','
   from have
   ;
quit;

%put &amp;amp;mvar.;&lt;/PRE&gt;
&lt;P&gt;The Proc SQL select into : places values into a macro variable, the "separated by" allows you to specify a string to place between values.&lt;/P&gt;</description>
    <pubDate>Tue, 31 Aug 2021 15:16:39 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-08-31T15:16:39Z</dc:date>
    <item>
      <title>Working with metadata, I have a list of columns I want to dynamically place in proc sql select?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-metadata-I-have-a-list-of-columns-I-want-to/m-p/765073#M242314</link>
      <description>&lt;P&gt;sas 9.4 for Windoes&lt;BR /&gt;Have data set list like so:&lt;BR /&gt;column_item_1&lt;/P&gt;
&lt;P&gt;column_item_2&lt;/P&gt;
&lt;P&gt;column_item_3&lt;/P&gt;
&lt;P&gt;column_item_4&lt;/P&gt;
&lt;P&gt;column_item_...&lt;/P&gt;
&lt;P&gt;column_item_n&lt;BR /&gt;&lt;BR /&gt;want:&lt;BR /&gt;%put &amp;amp;my_var.;&lt;BR /&gt;column_item_1, column_item_2, column_item_3, column_item_4, column_item_..., column_item_n&lt;BR /&gt;&lt;BR /&gt;Please note as needed 'proc sql' needs commas between columns but not after the last column, &lt;BR /&gt;The column count can change&lt;BR /&gt;Can get a count on the total length of the strings individual strings, and as a whole&lt;BR /&gt;Can get the total number of column_items&lt;BR /&gt;but they can and do change from run to run depending on table input.&lt;BR /&gt;TIA.&amp;nbsp;&amp;nbsp; -KJ&lt;BR /&gt;I have been trying with proc transpose to go from long to wide then use one of the cat-s but have not figure out the trick yet.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 15:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-metadata-I-have-a-list-of-columns-I-want-to/m-p/765073#M242314</guid>
      <dc:creator>kjohnsonm</dc:creator>
      <dc:date>2021-08-31T15:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Working with metadata, I have a list of columns I want to dynamically place in proc sql select?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-metadata-I-have-a-list-of-columns-I-want-to/m-p/765075#M242315</link>
      <description>&lt;P&gt;Not really clear what you are asking, but try this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
     select variablename into :my_var separated by ',' from list;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If that's not what you want, explain in more detail, lots more detail.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 15:12:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-metadata-I-have-a-list-of-columns-I-want-to/m-p/765075#M242315</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-31T15:12:38Z</dc:date>
    </item>
    <item>
      <title>Re: Working with metadata, I have a list of columns I want to dynamically place in proc sql select?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-metadata-I-have-a-list-of-columns-I-want-to/m-p/765079#M242316</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/43996"&gt;@kjohnsonm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;sas 9.4 for Windoes&lt;BR /&gt;Have data set list like so:&lt;BR /&gt;column_item_1&lt;/P&gt;
&lt;P&gt;column_item_2&lt;/P&gt;
&lt;P&gt;column_item_3&lt;/P&gt;
&lt;P&gt;column_item_4&lt;/P&gt;
&lt;P&gt;column_item_...&lt;/P&gt;
&lt;P&gt;column_item_n&lt;BR /&gt;&lt;BR /&gt;want:&lt;BR /&gt;%put &amp;amp;my_var.;&lt;BR /&gt;column_item_1, column_item_2, column_item_3, column_item_4, column_item_..., column_item_n&lt;BR /&gt;&lt;BR /&gt;Please note as needed 'proc sql' needs commas between columns but not after the last column, &lt;BR /&gt;The column count can change&lt;BR /&gt;Can get a count on the total length of the strings individual strings, and as a whole&lt;BR /&gt;Can get the total number of column_items&lt;BR /&gt;but they can and do change from run to run depending on table input.&lt;BR /&gt;TIA.&amp;nbsp;&amp;nbsp; -KJ&lt;BR /&gt;I have been trying with proc transpose to go from long to wide then use one of the cat-s but have not figure out the trick yet.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It certainly helps to provide such information as the name of your variable holding the values you want and the name of the data set.&lt;/P&gt;
&lt;P&gt;See below for an example that creates a data set similar to what you describe (hint: best practice to show data), and creates a macro variable as you request:&lt;/P&gt;
&lt;PRE&gt;data have;
   input name :$13.;
datalines;
column_item_1
column_item_2
column_item_3
column_item_4
column_item_5
column_item_n
;

proc sql noprint;
   select name into :mvar separated by ','
   from have
   ;
quit;

%put &amp;amp;mvar.;&lt;/PRE&gt;
&lt;P&gt;The Proc SQL select into : places values into a macro variable, the "separated by" allows you to specify a string to place between values.&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 15:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-metadata-I-have-a-list-of-columns-I-want-to/m-p/765079#M242316</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-31T15:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Working with metadata, I have a list of columns I want to dynamically place in proc sql select?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-metadata-I-have-a-list-of-columns-I-want-to/m-p/765086#M242317</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;You'll find what you need in the &lt;A href="https://v8doc.sas.com/sashtml/proc/zsqldict.htm" target="_blank" rel="noopener"&gt;dictionary tables&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;You'll get the list of columns with this query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL noprint;
   SELECT name INTO :my_var SEPARATED BY ', '
   FROM sashelp.vcolumn
   WHERE libname eq 'SASHELP'
   AND memname eq 'CLASS'
   ;
QUIT;

%put &amp;amp;=my_var;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 15:29:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-metadata-I-have-a-list-of-columns-I-want-to/m-p/765086#M242317</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-08-31T15:29:44Z</dc:date>
    </item>
  </channel>
</rss>

