<?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 count variables with similar name patten in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-variables-with-similar-name-patten/m-p/926011#M364389</link>
    <description>&lt;P&gt;If they are all of the same type (numeric or character does not matter) then a simple data step should do the job.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if 0 then set have;
  array __xx col: ;
  call symputx('colnum',dim(__xx));
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise you could try using the SAS dictionary metadata view/table to check.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select count(*) format=32. into :colnum trimmed
from dictionary.columns
where libname='WORK'
  and memname='HAVE'
  and upcase(name) eqt 'COL'
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 26 Apr 2024 13:50:39 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2024-04-26T13:50:39Z</dc:date>
    <item>
      <title>how to count variables with similar name patten</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-variables-with-similar-name-patten/m-p/926007#M364387</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I have a dataset which have a large amount variables with name like colXX. Is it a way to found out how many variables with this type of name and assign it to a macro variable COLNUM?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 13:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-variables-with-similar-name-patten/m-p/926007#M364387</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-04-26T13:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: how to count variables with similar name patten</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-variables-with-similar-name-patten/m-p/926011#M364389</link>
      <description>&lt;P&gt;If they are all of the same type (numeric or character does not matter) then a simple data step should do the job.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if 0 then set have;
  array __xx col: ;
  call symputx('colnum',dim(__xx));
  stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Otherwise you could try using the SAS dictionary metadata view/table to check.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select count(*) format=32. into :colnum trimmed
from dictionary.columns
where libname='WORK'
  and memname='HAVE'
  and upcase(name) eqt 'COL'
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 26 Apr 2024 13:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-variables-with-similar-name-patten/m-p/926011#M364389</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-26T13:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to count variables with similar name patten</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-variables-with-similar-name-patten/m-p/926017#M364392</link>
      <description>May I ask why we need to use 'if 0 then' instead of directly 'set have'?</description>
      <pubDate>Fri, 26 Apr 2024 13:59:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-variables-with-similar-name-patten/m-p/926017#M364392</guid>
      <dc:creator>stataq</dc:creator>
      <dc:date>2024-04-26T13:59:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to count variables with similar name patten</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-count-variables-with-similar-name-patten/m-p/926020#M364394</link>
      <description>&lt;P&gt;Since 0 is treated as FALSE by SAS the SET statement will never actually execute, but it will be checked by the data step compiler to find the list of variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Two reasons.&lt;/P&gt;
&lt;P&gt;1) If the HAVE dataset has zero observations the data step will stop at the SET statement and never execute the CALL SYMPUTX()&lt;/P&gt;
&lt;P&gt;2) If the HAVE dataset is large it might take more resources to actually read even just the first observation from it.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 14:06:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-count-variables-with-similar-name-patten/m-p/926020#M364394</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-04-26T14:06:43Z</dc:date>
    </item>
  </channel>
</rss>

