<?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: dynamically created variable list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66040#M14335</link>
    <description>&amp;gt; Unfortunately, I need to use this list to do things&lt;BR /&gt;
&amp;gt; like create define statements for proc report.  I&lt;BR /&gt;
&amp;gt; really need the list stored in a macro variable that&lt;BR /&gt;
&amp;gt; can be referenced&lt;BR /&gt;
&lt;BR /&gt;
Unfortunate?  What information do you need to supply for the DEFINE statements, you may be able to write generic define statements.  Consider the following...&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql noprint nowarn outobs=5 /*or 5*/;&lt;BR /&gt;
   select name into :names separated by ' '&lt;BR /&gt;
      from dictionary.columns&lt;BR /&gt;
      where libname eq 'SASHELP' and memname eq 'CLASS'&lt;BR /&gt;
      order by varnum&lt;BR /&gt;
      ;&lt;BR /&gt;
&lt;BR /&gt;
   quit;&lt;BR /&gt;
   run; &lt;BR /&gt;
%put NOTE: NAMES=&amp;amp;names;&lt;BR /&gt;
&lt;BR /&gt;
proc report data=sashelp.class(keep=&amp;amp;names) nowd list;&lt;BR /&gt;
   columns &amp;amp;names;&lt;BR /&gt;
   define _all_ / group;&lt;BR /&gt;
   define _numeric_ / format=comma12.;&lt;BR /&gt;
   define _character_ / format=$10.;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Or if that is inadequate you could "code gen" define statements in a way similar to the variable list &amp;amp;NAMES.  A bit more complicated by doable.</description>
    <pubDate>Fri, 21 Aug 2009 19:55:31 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2009-08-21T19:55:31Z</dc:date>
    <item>
      <title>dynamically created variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66035#M14330</link>
      <description>How do I dynamically specify a list of variables to keep in a dataset?&lt;BR /&gt;
&lt;BR /&gt;
I've created a file using proc contents that contains a list of variables.  I want to use this list in a data step but each time I run the program the list can change.&lt;BR /&gt;
&lt;BR /&gt;
For example I want to do something like this;&lt;BR /&gt;
&lt;BR /&gt;
data test (keep=v1 v2 v3 v4 v5); set old;  or I want to dynamically specify the columns in a proc report ie column v1 v2 v3 v4 v5.&lt;BR /&gt;
&lt;BR /&gt;
data set old may contain 10 variables but I only want the first 5. The list might be totally different next time so hard coding v1 to v5 would not work.</description>
      <pubDate>Fri, 21 Aug 2009 16:16:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66035#M14330</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-08-21T16:16:27Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically created variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66036#M14331</link>
      <description>proc sql;&lt;BR /&gt;
&lt;BR /&gt;
select name into :vlist separated by " " from dictionary.columns&lt;BR /&gt;
where libname = 'WORK' and memname = 'TEST';&lt;BR /&gt;
quit;&lt;BR /&gt;
%put &amp;amp;vlist;</description>
      <pubDate>Fri, 21 Aug 2009 16:37:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66036#M14331</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-08-21T16:37:03Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically created variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66037#M14332</link>
      <description>Explore using the DICTIONARY TABLES with PROC SQL to build a SAS macro variable with the required variable(s) you desire.  Use this Google advanced search argument to find related DOC and technical articles/papers on the SAS support website at &lt;A href="http://support.sas.com/" target="_blank"&gt;http://support.sas.com/&lt;/A&gt; :&lt;BR /&gt;
&lt;BR /&gt;
proc sql dictionary tables site:sas.com&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Fri, 21 Aug 2009 16:38:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66037#M14332</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-08-21T16:38:19Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically created variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66038#M14333</link>
      <description>You probably don't need to create a new data set just get the list of names.  You want the 5 left most by position in the data set right?  &lt;BR /&gt;
&lt;BR /&gt;
 &lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql noprint nowarn outobs=3 /*or 5*/;&lt;BR /&gt;
   select name into :names separated by ' '&lt;BR /&gt;
      from dictionary.columns&lt;BR /&gt;
      where libname eq 'SASHELP' and memname eq 'CLASS'&lt;BR /&gt;
      order by varnum&lt;BR /&gt;
      ;&lt;BR /&gt;
&lt;BR /&gt;
   quit;&lt;BR /&gt;
   run; &lt;BR /&gt;
%put NOTE: NAMES=&amp;amp;names;&lt;BR /&gt;
&lt;BR /&gt;
proc report data=sashelp.class nowd;&lt;BR /&gt;
   columns &amp;amp;names;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Fri, 21 Aug 2009 16:48:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66038#M14333</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-08-21T16:48:10Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically created variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66039#M14334</link>
      <description>Ah figured out why it was not working for me&lt;BR /&gt;
&lt;BR /&gt;
the sql is case sensitive and I had typed in the name of my dataset in lower case.&lt;BR /&gt;
&lt;BR /&gt;
Unfortunately, I need to use this list to do things like create define statements for proc report.  I really need the list stored in a macro variable that can be referenced</description>
      <pubDate>Fri, 21 Aug 2009 18:24:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66039#M14334</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-08-21T18:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: dynamically created variable list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66040#M14335</link>
      <description>&amp;gt; Unfortunately, I need to use this list to do things&lt;BR /&gt;
&amp;gt; like create define statements for proc report.  I&lt;BR /&gt;
&amp;gt; really need the list stored in a macro variable that&lt;BR /&gt;
&amp;gt; can be referenced&lt;BR /&gt;
&lt;BR /&gt;
Unfortunate?  What information do you need to supply for the DEFINE statements, you may be able to write generic define statements.  Consider the following...&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
proc sql noprint nowarn outobs=5 /*or 5*/;&lt;BR /&gt;
   select name into :names separated by ' '&lt;BR /&gt;
      from dictionary.columns&lt;BR /&gt;
      where libname eq 'SASHELP' and memname eq 'CLASS'&lt;BR /&gt;
      order by varnum&lt;BR /&gt;
      ;&lt;BR /&gt;
&lt;BR /&gt;
   quit;&lt;BR /&gt;
   run; &lt;BR /&gt;
%put NOTE: NAMES=&amp;amp;names;&lt;BR /&gt;
&lt;BR /&gt;
proc report data=sashelp.class(keep=&amp;amp;names) nowd list;&lt;BR /&gt;
   columns &amp;amp;names;&lt;BR /&gt;
   define _all_ / group;&lt;BR /&gt;
   define _numeric_ / format=comma12.;&lt;BR /&gt;
   define _character_ / format=$10.;&lt;BR /&gt;
   run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Or if that is inadequate you could "code gen" define statements in a way similar to the variable list &amp;amp;NAMES.  A bit more complicated by doable.</description>
      <pubDate>Fri, 21 Aug 2009 19:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/dynamically-created-variable-list/m-p/66040#M14335</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2009-08-21T19:55:31Z</dc:date>
    </item>
  </channel>
</rss>

