<?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 Column name change dynamically in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Column-name-change-dynamically/m-p/68379#M14821</link>
    <description>DATA multdat;&lt;BR /&gt;
FORMAT date mmddyy10.;&lt;BR /&gt;
INPUT id $ date mmddyy10. T1 T2 T3 T4 T5 T6;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
A1 11/01/2004 223 204 195  196 197 200&lt;BR /&gt;
A2 11/01/2004 211 192 183  196 197 200&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
DATA univdat;&lt;BR /&gt;
SET multdat;&lt;BR /&gt;
ARRAY TEST{*} T1-T6;&lt;BR /&gt;
KEEP id date  RESULT;&lt;BR /&gt;
 DO i = 1 to dim(TEST);&lt;BR /&gt;
    RESULT=TEST(i);&lt;BR /&gt;
   OUTPUT;    &lt;BR /&gt;
 END;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
The above code works fine as long as the number of variables for array name test remain the same.There could be less or more variables. next month I may get only 3 values T1 to T3? or I may get more than 6? How to assign an upper bound to the variable T?</description>
    <pubDate>Mon, 31 Aug 2009 16:49:24 GMT</pubDate>
    <dc:creator>SASPhile</dc:creator>
    <dc:date>2009-08-31T16:49:24Z</dc:date>
    <item>
      <title>Column name change dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-name-change-dynamically/m-p/68379#M14821</link>
      <description>DATA multdat;&lt;BR /&gt;
FORMAT date mmddyy10.;&lt;BR /&gt;
INPUT id $ date mmddyy10. T1 T2 T3 T4 T5 T6;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
A1 11/01/2004 223 204 195  196 197 200&lt;BR /&gt;
A2 11/01/2004 211 192 183  196 197 200&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
DATA univdat;&lt;BR /&gt;
SET multdat;&lt;BR /&gt;
ARRAY TEST{*} T1-T6;&lt;BR /&gt;
KEEP id date  RESULT;&lt;BR /&gt;
 DO i = 1 to dim(TEST);&lt;BR /&gt;
    RESULT=TEST(i);&lt;BR /&gt;
   OUTPUT;    &lt;BR /&gt;
 END;&lt;BR /&gt;
RUN;&lt;BR /&gt;
&lt;BR /&gt;
The above code works fine as long as the number of variables for array name test remain the same.There could be less or more variables. next month I may get only 3 values T1 to T3? or I may get more than 6? How to assign an upper bound to the variable T?</description>
      <pubDate>Mon, 31 Aug 2009 16:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-name-change-dynamically/m-p/68379#M14821</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-08-31T16:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Column name change dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-name-change-dynamically/m-p/68380#M14822</link>
      <description>How about something like this?&lt;BR /&gt;
&lt;BR /&gt;
Proc sql;&lt;BR /&gt;
select max(input(subtr(name, 2), best.) into : tlim&lt;BR /&gt;
from dictionary.columns where libname = "WORK" and memname = "MULTDAT"&lt;BR /&gt;
and substr(name , 1,1) = 'T';&lt;BR /&gt;
&lt;BR /&gt;
then use &amp;amp;tlim &lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Warning: code off the top of my head may contain errors;}</description>
      <pubDate>Mon, 31 Aug 2009 17:01:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-name-change-dynamically/m-p/68380#M14822</guid>
      <dc:creator>Flip</dc:creator>
      <dc:date>2009-08-31T17:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Column name change dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-name-change-dynamically/m-p/68381#M14823</link>
      <description>Flip,&lt;BR /&gt;
 I tried this and it worked:&lt;BR /&gt;
&lt;BR /&gt;
DATA multdat;&lt;BR /&gt;
FORMAT date mmddyy10.;&lt;BR /&gt;
INPUT id $ date mmddyy10. T1 T2 T3 T4 T5 T6 T7;&lt;BR /&gt;
CARDS;&lt;BR /&gt;
A1 11/01/2004 223 204 195  196 197 200 300&lt;BR /&gt;
A2 11/01/2004 211 192 183  196 197 200 300&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
proc sql;&lt;BR /&gt;
 select count(*) into:up from sashelp.vcolumn where libname='WORK' and memname='MULTDAT' and&lt;BR /&gt;
  name like '%T%';&lt;BR /&gt;
  quit;&lt;BR /&gt;
  %put &amp;amp;up.;&lt;BR /&gt;
%macro try;&lt;BR /&gt;
DATA univdat;&lt;BR /&gt;
SET multdat;&lt;BR /&gt;
&lt;BR /&gt;
ARRAY TEST{*} T1-%sysfunc(compress(T&amp;amp;up.));&lt;BR /&gt;
KEEP id date  RESULT;&lt;BR /&gt;
 DO i = 1 to dim(TEST);&lt;BR /&gt;
    RESULT=TEST(i);&lt;BR /&gt;
   OUTPUT;    &lt;BR /&gt;
 END;&lt;BR /&gt;
RUN;&lt;BR /&gt;
%mend try;&lt;BR /&gt;
%try;</description>
      <pubDate>Mon, 31 Aug 2009 17:15:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-name-change-dynamically/m-p/68381#M14823</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2009-08-31T17:15:46Z</dc:date>
    </item>
    <item>
      <title>Re: Column name change dynamically</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Column-name-change-dynamically/m-p/68382#M14824</link>
      <description>Consider that if you have control over the SAS variables named in your DATA step and SAS dataset, you can define an ARRAY statement with a variable prefix, such as:&lt;BR /&gt;
&lt;BR /&gt;
ARRAY ATNNN (*) T:  ;&lt;BR /&gt;
&lt;BR /&gt;
but you would not be able to have any other variables (not in the array nor of a different SAS variable type) defined in the SAS dataset.&lt;BR /&gt;
&lt;BR /&gt;
Clearly this technique may or may not apply, but it is possible with some programming instances.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Mon, 31 Aug 2009 17:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Column-name-change-dynamically/m-p/68382#M14824</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-08-31T17:41:35Z</dc:date>
    </item>
  </channel>
</rss>

