<?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 write a macro to count the variables in the end? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366343#M64852</link>
    <description>&lt;P&gt;It's not one-time use. &amp;nbsp;I will use it every month. &amp;nbsp;In additions, the data sets will come from different sources. &amp;nbsp;For example, one comes to '&lt;SPAN&gt;Gm_go' with 5 and the other comes to 'Gm_go' with 7. &amp;nbsp;In that way, I need to count it by myself if I don't set up a macro. &amp;nbsp;I am trying to find if there is a shortcut for counting.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Jun 2017 21:16:24 GMT</pubDate>
    <dc:creator>ybz12003</dc:creator>
    <dc:date>2017-06-12T21:16:24Z</dc:date>
    <item>
      <title>How to write a macro to count the variables in the end?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366306#M64840</link>
      <description>&lt;P&gt;Hello, experts:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have the follow macro program to change the column names. However, I have to manually count each variables to write the number at the end to make the macro program run. Is there a way the detect the how many variables and input the number automatically? Please see my attachment for details, the Oldprefix tab is needed to be corrected.&amp;nbsp;&amp;nbsp; And the Newprefix tab is the standard name. The excel sheets are only the examples.&amp;nbsp;&amp;nbsp; My actual dataset contains 30 variables which are very similar situation need to be changed. Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;Y&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; rename(oldprefix, newprefix, num);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; k=1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%do&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%while&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(&amp;amp;k &amp;lt;= &amp;amp;num);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;rename &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;oldprefix.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;amp;k = &amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;newprefix.&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;&amp;amp;k;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; k = &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;(&amp;amp;k + 1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;%end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; rename;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; a ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; il; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;%&lt;STRONG&gt;&lt;I&gt;rename&lt;/I&gt;&lt;/STRONG&gt;(Gm_go, Yut_go,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;%&lt;STRONG&gt;&lt;I&gt;rename&lt;/I&gt;&lt;/STRONG&gt;(gm_hhrt, Comp_notes_1,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;%&lt;STRONG&gt;&lt;I&gt;rename&lt;/I&gt;&lt;/STRONG&gt;(gm_certificate, Data_certific,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 19:28:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366306#M64840</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-12T19:28:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro to count the variables in the end?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366310#M64841</link>
      <description>&lt;P&gt;Small example&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let nvar=%sysfunc(attrn(%sysfunc(open(sashelp.cars)),nvar));
%put &amp;amp;nvar ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Jun 2017 19:33:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366310#M64841</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-06-12T19:33:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro to count the variables in the end?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366338#M64848</link>
      <description>&lt;P&gt;As long as you have to do the counting, just get rid of all the macro language entirely.&amp;nbsp; You can code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;rename Gm_go1- Gm_go5 = Yut_go1 - Yut_go5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you are going to run something like this many times, with different variables each time, we can revisit how to write a macro.&amp;nbsp; But so far it's not worth the effort for a one-time application.&amp;nbsp; You could write 30 RENAME statements faster than you could write, debug, and apply a macro for that purpose.&amp;nbsp; And remember, you don't have to count them.&amp;nbsp; PROC CONTENTS will list the names for you, complete with options that print the variable names in order according to the value of the numeric suffix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Note: &amp;nbsp;Sorry, I can't program this for you. &amp;nbsp;Coding, testing, and explaining would take an hour, and I'm just not willing to spend that amount of time on it.&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 01:44:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366338#M64848</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-06-13T01:44:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro to count the variables in the end?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366341#M64850</link>
      <description>&lt;P&gt;The codes you gave seems only count all of the variables. &amp;nbsp;I am looking for some specific varaibles.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 21:12:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366341#M64850</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-12T21:12:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro to count the variables in the end?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366343#M64852</link>
      <description>&lt;P&gt;It's not one-time use. &amp;nbsp;I will use it every month. &amp;nbsp;In additions, the data sets will come from different sources. &amp;nbsp;For example, one comes to '&lt;SPAN&gt;Gm_go' with 5 and the other comes to 'Gm_go' with 7. &amp;nbsp;In that way, I need to count it by myself if I don't set up a macro. &amp;nbsp;I am trying to find if there is a shortcut for counting.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2017 21:16:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366343#M64852</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-12T21:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro to count the variables in the end?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366413#M64862</link>
      <description>&lt;P&gt;What specific varaibles are these? I don't want to download Excel files &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 07:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366413#M64862</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-06-13T07:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro to count the variables in the end?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366420#M64863</link>
      <description>&lt;P&gt;Find below sample code that shows some techniques on counting the number of variables that have a certain name. The example makes use of dictionary tables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length
    somevar1 $ 1
    other $ 2
    abc $ 3
  ;
  array gm_go{4};
run;

proc sql;
  select
    libname
    , memname
    , name
  from
    dictionary.columns
  where
    libname = "WORK"
    and memname = "HAVE"
    and lowcase(name) like 'gm_go%'
  ;

  %put NOTE: &amp;amp;=sqlrc &amp;amp;=sqlobs;

  reset noprint;
  select
    count(*)
    into
    :nVars trimmed
  from
    dictionary.columns
  where
    libname = "WORK"
    and memname = "HAVE"
    and lowcase(name) like 'gm_go%'
  ;
  %put NOTE: *&amp;amp;nVars*;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 13 Jun 2017 07:53:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366420#M64863</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-06-13T07:53:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro to count the variables in the end?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366498#M64868</link>
      <description>&lt;P&gt;Awesome!&amp;nbsp; I will look into this.&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 12:15:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366498#M64868</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-13T12:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to write a macro to count the variables in the end?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366503#M64869</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;Acturally, I use proc contents to put all of the columns names in vertical way, then 'where' statement and then proc mean to count each group.&amp;nbsp; But I found the 'Name' only contains '&lt;FONT face="Courier New" size="2"&gt;gm_certificate&lt;/FONT&gt;' in the end.&amp;nbsp; Is there way keep all of the group names,&amp;nbsp;including &lt;FONT color="#800080"&gt;&lt;FONT face="Courier New" size="2"&gt;'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;Gm_go&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;'&lt;/FONT&gt;&lt;/FONT&gt;,&lt;FONT color="#800080"&gt;&lt;FONT face="Courier New" size="2"&gt;'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;gm_hhrt&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;'&lt;/FONT&gt;&lt;/FONT&gt;, and&amp;nbsp;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'gm_certificate'&lt;/FONT&gt;,&amp;nbsp;&amp;nbsp;in the column 'Name'?&amp;nbsp; Thanks.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;contents&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=oldname &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;out&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=have (keep=NAME);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; count;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; have;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; name contains &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'&lt;FONT face="Courier New" size="2"&gt;Gm_go&lt;/FONT&gt;'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; N1=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;where&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; name contains &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="2"&gt;'&lt;FONT face="Courier New" size="2"&gt;gm_hhrt&lt;/FONT&gt;'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; N2=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;where&lt;/FONT&gt; name contains &lt;FONT color="#800080" face="Courier New" size="2"&gt;'gm_certificate'&lt;/FONT&gt;; N3=&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="2"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;means&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="2"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;=count &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;sum&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="2"&gt;var&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; N1 N2 N3;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="2"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2017 12:25:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-write-a-macro-to-count-the-variables-in-the-end/m-p/366503#M64869</guid>
      <dc:creator>ybz12003</dc:creator>
      <dc:date>2017-06-13T12:25:21Z</dc:date>
    </item>
  </channel>
</rss>

