<?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: Run macro on 24 months and 100 variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-on-24-months-and-100-variables/m-p/924497#M363903</link>
    <description>&lt;P&gt;No macros needed! I like it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No SQL needed, I like it even more!&lt;/P&gt;</description>
    <pubDate>Tue, 16 Apr 2024 13:37:10 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2024-04-16T13:37:10Z</dc:date>
    <item>
      <title>Run macro on 24 months and 100 variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-on-24-months-and-100-variables/m-p/924474#M363896</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;In real&amp;nbsp; situation I have 24 data sets (Names ABC with YYYMM) and 100 variables.&lt;/P&gt;
&lt;P&gt;Here is code that calculate for each data set source and numeric variable&amp;nbsp; the following statistics:&lt;/P&gt;
&lt;P&gt;Number of rows&lt;/P&gt;
&lt;P&gt;Number of rows with missing value&lt;/P&gt;
&lt;P&gt;Number of rows with Positive value&lt;/P&gt;
&lt;P&gt;Number of rows with negative value&lt;/P&gt;
&lt;P&gt;number of distinct values (included null value)&lt;/P&gt;
&lt;P&gt;The problem is that I need to run on 24 months and on 100 variables.&lt;/P&gt;
&lt;P&gt;My question-&lt;/P&gt;
&lt;P&gt;Can you show the efficient way (less code rows) to run this macro?&lt;/P&gt;
&lt;P&gt;Here I run it with 12 rows of macro run but I guess it can be done with one row only.&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
Data ABC202401;
Input ID X Y Z;
cards;
1 10 20 30
2 11 21 31
3 12 31 41
4 10 15 20
5 30 40 50
6 5 10 .
7 . . -100

;
Run;

Data ABC202402;
Input ID X Y Z;
cards;
1 15 30 17
2 18 21 43
3 31 50 41
3 8 18 28
;
Run;

Data ABC202403;
Input ID X Y Z;
cards;
1 43 23 62
2 21 16 .
3 47 50 .
4 -10 -20 -30
;
Run;


Data ABC202404;
Input ID X Y Z;
cards;
1 -70 14 62
2 -15 42 45
3 27 . .
;
Run;




%macro RRR_numeric_vars(month,VAR);
proc sql;
create table _summary_ as
select  "&amp;amp;Var." as var,"&amp;amp;month." as month,
        count(*) as nr_Rows,
        sum(case when &amp;amp;Var.&amp;gt;0 then 1 else 0 end ) as nr_Rows_POS,
        sum(case when &amp;amp;Var.=0 then 1 else 0 end ) as nr_Rows_ZERO,
        sum(case when &amp;amp;Var.&amp;lt;0 AND &amp;amp;Var. ne .  then 1 else 0 end ) as nr_Rows_NEG_no_missig,
		sum(case when &amp;amp;Var.=. then 1 else 0 end ) as nr_Rows_Missing
from ABC&amp;amp;month.
;
quit;
proc append data=_summary_ base=Summary_All force;quit;
%mend RRR_numeric_vars;
/*proc delete data=Summary_All;Run;*/
%RRR_numeric_vars(month=202401,VAR=X);
%RRR_numeric_vars(month=202402,VAR=X);
%RRR_numeric_vars(month=202403,VAR=X);
%RRR_numeric_vars(month=202404,VAR=X);

%RRR_numeric_vars(month=202401,VAR=Y);
%RRR_numeric_vars(month=202402,VAR=Y);
%RRR_numeric_vars(month=202403,VAR=Y);
%RRR_numeric_vars(month=202404,VAR=Y);

%RRR_numeric_vars(month=202401,VAR=Z);
%RRR_numeric_vars(month=202402,VAR=Z);
%RRR_numeric_vars(month=202403,VAR=Z);
%RRR_numeric_vars(month=202404,VAR=Z);

proc print data=Summary_All noobs;Run;

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Apr 2024 12:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-on-24-months-and-100-variables/m-p/924474#M363896</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-04-16T12:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro on 24 months and 100 variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-on-24-months-and-100-variables/m-p/924484#M363897</link>
      <description>&lt;P&gt;How big is your data?&amp;nbsp; Would it be feasible to concatenate your 24 datasets into one dataset, create a variable that with YYYMM, then get the counts you want using PROC FREQ or one SQL step?&amp;nbsp; Something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data abc ;
  set abc20:  indsname=dsname;
  source=dsname ;
run ;

proc format ;
  value negpos
        low - &amp;lt; 0 ='Negative'
        0 - high = 'Positive'
        ._-.Z='Missing' 
  ;
run ;

proc freq data=abc nlev;
  tables x y z/missing list ;
  by source ;
  format x y z negpos. ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Apr 2024 12:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-on-24-months-and-100-variables/m-p/924484#M363897</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2024-04-16T12:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro on 24 months and 100 variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-on-24-months-and-100-variables/m-p/924497#M363903</link>
      <description>&lt;P&gt;No macros needed! I like it!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No SQL needed, I like it even more!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 13:37:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-on-24-months-and-100-variables/m-p/924497#M363903</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-04-16T13:37:10Z</dc:date>
    </item>
    <item>
      <title>Re: Run macro on 24 months and 100 variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Run-macro-on-24-months-and-100-variables/m-p/924499#M363905</link>
      <description>&lt;P&gt;Suggest use of: TABLES _NUMERIC_ / missing list;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming the "100" variables meant all the numeric variables. Then don't even need to know the names.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 13:41:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Run-macro-on-24-months-and-100-variables/m-p/924499#M363905</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-04-16T13:41:00Z</dc:date>
    </item>
  </channel>
</rss>

