<?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: how to get the max number in a column name. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12992#M1475</link>
    <description>Do these variables have the same type of data?&lt;BR /&gt;
If they are, You can use array to get it. It suited for var1-varN.&lt;BR /&gt;
Some dummy code like this:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
array sls{*} sls:;&lt;BR /&gt;
 max_number=dim(sls);&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
    <pubDate>Fri, 25 Feb 2011 05:00:05 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2011-02-25T05:00:05Z</dc:date>
    <item>
      <title>how to get the max number in a column name.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12987#M1470</link>
      <description>how to get the max number in a column name.&lt;BR /&gt;
say for instance if  there are columns sls1 to sls12, how to get the number 12 from the  column name sls12?</description>
      <pubDate>Fri, 18 Feb 2011 15:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12987#M1470</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2011-02-18T15:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the max number in a column name.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12988#M1471</link>
      <description>&amp;gt; how to get the max number in a column name.&lt;BR /&gt;
&amp;gt; say for instance if  there are columns sls1 to sls12,&lt;BR /&gt;
&amp;gt; how to get the number 12 from the  column name sls12?&lt;BR /&gt;
&lt;BR /&gt;
I think the short answer is use VNAME function.  But I assume you want a method that allows you retrieve the dimension of the enurmerated list no matter what it is.  To do that you need to give a little more information on what you have and what you know.</description>
      <pubDate>Fri, 18 Feb 2011 15:33:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12988#M1471</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2011-02-18T15:33:59Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the max number in a column name.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12989#M1472</link>
      <description>The reason is to rename the variables.i.e  12 months of sales we will have sls1 to sls12. after 12 months, the 13th month we will have new sales data and that will be called as sls1.&lt;BR /&gt;
and the previous months sales will be named from there on. i.e sls1  has to be renamed  sls2, sls2 has to be renamed as sls3 so on.</description>
      <pubDate>Fri, 18 Feb 2011 15:48:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12989#M1472</guid>
      <dc:creator>SASPhile</dc:creator>
      <dc:date>2011-02-18T15:48:12Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the max number in a column name.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12990#M1473</link>
      <description>please check the vcolumn view from sashelp.  This is a system created view which has an entry for every column, i mean each row represents a column in a table for all the active library in that session.&lt;BR /&gt;
&lt;BR /&gt;
Lets say your table is sales_yrly&lt;BR /&gt;
&lt;BR /&gt;
/*Creating SALES data */&lt;BR /&gt;
data SLS_YRLY;&lt;BR /&gt;
array sls{12};&lt;BR /&gt;
do j=1 to 10;&lt;BR /&gt;
do i=1 to dim(sls);&lt;BR /&gt;
 sls{i}= floor(ranuni(0)*60);&lt;BR /&gt;
end;&lt;BR /&gt;
output;&lt;BR /&gt;
end;&lt;BR /&gt;
drop i j;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql;&lt;BR /&gt;
select COUNT(name) INTO :MAX_SLS_COL  from sashelp.Vcolumn where libname='WORK'&lt;BR /&gt;
and memname='SLS_YRLY' and UPCASE(name) like 'SLS%' ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
%PUT &amp;amp;MAX_SLS_COL.;&lt;BR /&gt;
&lt;BR /&gt;
Hope this helps!</description>
      <pubDate>Tue, 22 Feb 2011 21:10:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12990#M1473</guid>
      <dc:creator>jonam</dc:creator>
      <dc:date>2011-02-22T21:10:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the max number in a column name.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12991#M1474</link>
      <description>I think you would find it easier to manage the data with the month as a date column (i.e. transposed to "narrow").&lt;BR /&gt;
Let the reporting procedures (like REPORT and TABULATE) achieve the transpose of 12 rows into 12 columns. (easy as class or accross variables). Then your filtering is simply for sales within whatever date range is needed. &lt;BR /&gt;
I would even encourage you to transpose any preliminary data delivered in a "wide" form, back to "narrow" to better support trend analysis. &lt;BR /&gt;
Holding a "monthly" categorical variable as a SAS date will ensure you can keep proper chronological order ( imagine arranging MonYY month strings ) with any month-type format. Then, whether your months history is 1-12 or 2-13, is no longer important.&lt;BR /&gt;
just my $0.02&lt;BR /&gt;
peterC</description>
      <pubDate>Wed, 23 Feb 2011 10:05:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12991#M1474</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-02-23T10:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the max number in a column name.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12992#M1475</link>
      <description>Do these variables have the same type of data?&lt;BR /&gt;
If they are, You can use array to get it. It suited for var1-varN.&lt;BR /&gt;
Some dummy code like this:&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
array sls{*} sls:;&lt;BR /&gt;
 max_number=dim(sls);&lt;BR /&gt;
&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
Ksharp

Message was edited by: Ksharp</description>
      <pubDate>Fri, 25 Feb 2011 05:00:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12992#M1475</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2011-02-25T05:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: how to get the max number in a column name.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12993#M1476</link>
      <description>&amp;gt; &lt;B&gt;The reason is to rename the variables&lt;/B&gt;.i.e  12 months&lt;BR /&gt;
&amp;gt; of sales we will have sls1 to sls12. after 12 months,&lt;BR /&gt;
&amp;gt; the 13th month we will have new sales data and that&lt;BR /&gt;
&amp;gt; will be called as sls1.&lt;BR /&gt;
&amp;gt; and the previous months sales will be named from&lt;BR /&gt;
&amp;gt; there on. i.e sls1  has to be renamed  sls2, sls2 has&lt;BR /&gt;
&amp;gt; to be renamed as sls3 so on.&lt;BR /&gt;
&lt;BR /&gt;
are you seeking a renaming shortcut?&lt;BR /&gt;
from a table holding columns sls1 - sls&amp;amp;n which are to be renamed as sls2 - sls%eval( &amp;amp;n +1 )&lt;BR /&gt;
???&lt;BR /&gt;
(if you have SAS9.2 rename in ranges works) try[pre]&lt;BR /&gt;
libname your (work) ;[/pre]*first create data set with columns sls1-sls12;[pre]data your.original ;&lt;BR /&gt;
 retain sls1-sls12 123 ;&lt;BR /&gt;
run;&lt;BR /&gt;
proc contents data= your.original noprint out= _data_ ; run; [/pre]* getting column names;[pre]proc sql noprint ;&lt;BR /&gt;
select max( input(substr( name, 4, 3), 3.)) into :N separated by ' '[/pre]without that input function, I got the maximum of the string which was 9, but we want 12[pre]from &amp;amp;syslast where lowcase(substr(name,1,3)) = "sls"&lt;BR /&gt;
;&lt;BR /&gt;
quit ;[/pre]* finally build new table renaming columns;[pre]data new_names ;&lt;BR /&gt;
  set your.original( rename= ( sls1-sls&amp;amp;N = _sls1-_sls&amp;amp;N ) );&lt;BR /&gt;
  rename   _sls1-_sls&amp;amp;N = sls2-sls%eval( &amp;amp;N +1 )  ;&lt;BR /&gt;
run;[/pre] needed the two stage rename at the end because it seems to validate each rename within the statement.</description>
      <pubDate>Fri, 25 Feb 2011 10:46:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-get-the-max-number-in-a-column-name/m-p/12993#M1476</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-02-25T10:46:41Z</dc:date>
    </item>
  </channel>
</rss>

