<?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: nr_null nr_zero,nr_POS,nr_NEG for each numeric var in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/m-p/929721#M83481</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Seems like this is answered in your other thread.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Indeed ... and that other thread is&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/td-p/929381" target="_blank"&gt;Solved: Wide to Long - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Still I have re-written the program without first transposing from wide to long.&lt;BR /&gt;The program is to be considered un-tested as SASHELP.CLASS is a bad choice for developing and testing the approach (no missing values, no zeros, ...).&lt;/P&gt;
&lt;P&gt;Other remark : program goes through the full data (again) with every macro call. If your data is big data, you might want to re-write such that program goes through the data only once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC DATASETS library=WORK NoList NoDetails memtype=DATA;
 delete want_summary_Report_: ; run;
 delete distinct_levels_:     ; run;
 delete profil                ; run;
run; QUIT;

%MACRO profil(checknm=nulls , checkop=EQ .);
data work.want_summary_Report_&amp;amp;checknm.(keep=nr_&amp;amp;checknm._age nr_&amp;amp;checknm._height nr_&amp;amp;checknm._weight);
 set sashelp.class end=last;
*array in{*}  _NUMERIC_;
 array in{3}  age height weight;
 array out{3} _TEMPORARY_ ;
/* Temporary data element values are always automatically retained, */ 
/* rather than being reset to missing at the beginning              */ 
/* of the next iteration of the DATA step.                          */
 do i=1 to dim(in);
  if _N_ = 1 then do; out(i)=0; end;
  if      i=1 and in(i) &amp;amp;checkop. then out(i) = out(i) + 1;
  else if i=2 and in(i) &amp;amp;checkop. then out(i) = out(i) + 1;
  else if i=3 and in(i) &amp;amp;checkop. then out(i) = out(i) + 1;
  else;
 end;
 if last then do; 
  nr_&amp;amp;checknm._age    = out(1); 
  nr_&amp;amp;checknm._height = out(2); 
  nr_&amp;amp;checknm._weight = out(3); 
  output;
 end;
run;
PROC DATASETS library=WORK NoList NoDetails memtype=DATA;
 modify want_summary_Report_&amp;amp;checknm.;
  rename nr_&amp;amp;checknm._age    = age;
  rename nr_&amp;amp;checknm._height = height;
  rename nr_&amp;amp;checknm._weight = weight;
run; QUIT;
%MEND  profil;

%profil(checknm=nulls , checkop=EQ .);
%profil(checknm=zeros , checkop=EQ 0);
%profil(checknm=negw0 , checkop=LT 0);
%profil(checknm=posw0 , checkop=GT 0);

proc transpose data=want_summary_Report_nulls 
                out=want_summary_Report_nulls_tp(rename=(COL1=nr_nulls)); run;
proc transpose data=want_summary_Report_zeros 
                out=want_summary_Report_zeros_tp(rename=(COL1=nr_zeros)); run;
proc transpose data=want_summary_Report_negw0 
                out=want_summary_Report_negw0_tp(rename=(COL1=nr_negw0)); run;
proc transpose data=want_summary_Report_posw0 
                out=want_summary_Report_posw0_tp(rename=(COL1=nr_posw0)); run;

data profil;
 merge work.want_summary_Report_nulls_tp
       work.want_summary_Report_zeros_tp
	   work.want_summary_Report_negw0_tp
	   work.want_summary_Report_posw0_tp;
 by _NAME_;
 label _NAME_="Variable profiled";
run;

proc freq data=sashelp.class nlevels noprint;
 tables age    / out=work.distinct_levels_age;
 tables height / out=work.distinct_levels_height;
 tables weight / out=work.distinct_levels_weight;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
    <pubDate>Sun, 26 May 2024 12:17:34 GMT</pubDate>
    <dc:creator>sbxkoenk</dc:creator>
    <dc:date>2024-05-26T12:17:34Z</dc:date>
    <item>
      <title>nr_null nr_zero,nr_POS,nr_NEG for each numeric var</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/m-p/929701#M83479</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;In want to calculate statistics for all numeric variables.&lt;/P&gt;
&lt;P&gt;There are some statistics that I don't know how to calculate for each numeric variable -&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Number of rows with zero value (nr_Zero)&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Number of rows with missing value (nr_Null)&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Number of rows with positive value (nr_POS)&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Number of rows with negative value that is not null (nr_Zero)&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to calculate it automatically for each numeric var?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc means data=sashelp.class sum min max q1 median q3  P1 p5 p95 P99 P75 P25 cv SUM Range N mean std  STACKODSOUTPUT maxdec=2;
var _numeric_;
ods output summary=Want1(Rename=(Variable=Var_Name));
run;


ods output nlevels=LEVELS;
proc freq data=sashelp.class nlevels;
tables _numeric_ / noprint ;
run;

Nr_Null
Nr_Zero
Nr_POS
Nr_Neg&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 May 2024 07:03:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/m-p/929701#M83479</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2024-05-26T07:03:06Z</dc:date>
    </item>
    <item>
      <title>Re: nr_null nr_zero,nr_POS,nr_NEG for each numeric var</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/m-p/929710#M83480</link>
      <description>&lt;P&gt;Seems like this is answered in your other thread.&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 10:41:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/m-p/929710#M83480</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2024-05-26T10:41:53Z</dc:date>
    </item>
    <item>
      <title>Re: nr_null nr_zero,nr_POS,nr_NEG for each numeric var</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/m-p/929721#M83481</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Seems like this is answered in your other thread.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Indeed ... and that other thread is&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Wide-to-Long/td-p/929381" target="_blank"&gt;Solved: Wide to Long - SAS Support Communities&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Still I have re-written the program without first transposing from wide to long.&lt;BR /&gt;The program is to be considered un-tested as SASHELP.CLASS is a bad choice for developing and testing the approach (no missing values, no zeros, ...).&lt;/P&gt;
&lt;P&gt;Other remark : program goes through the full data (again) with every macro call. If your data is big data, you might want to re-write such that program goes through the data only once.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC DATASETS library=WORK NoList NoDetails memtype=DATA;
 delete want_summary_Report_: ; run;
 delete distinct_levels_:     ; run;
 delete profil                ; run;
run; QUIT;

%MACRO profil(checknm=nulls , checkop=EQ .);
data work.want_summary_Report_&amp;amp;checknm.(keep=nr_&amp;amp;checknm._age nr_&amp;amp;checknm._height nr_&amp;amp;checknm._weight);
 set sashelp.class end=last;
*array in{*}  _NUMERIC_;
 array in{3}  age height weight;
 array out{3} _TEMPORARY_ ;
/* Temporary data element values are always automatically retained, */ 
/* rather than being reset to missing at the beginning              */ 
/* of the next iteration of the DATA step.                          */
 do i=1 to dim(in);
  if _N_ = 1 then do; out(i)=0; end;
  if      i=1 and in(i) &amp;amp;checkop. then out(i) = out(i) + 1;
  else if i=2 and in(i) &amp;amp;checkop. then out(i) = out(i) + 1;
  else if i=3 and in(i) &amp;amp;checkop. then out(i) = out(i) + 1;
  else;
 end;
 if last then do; 
  nr_&amp;amp;checknm._age    = out(1); 
  nr_&amp;amp;checknm._height = out(2); 
  nr_&amp;amp;checknm._weight = out(3); 
  output;
 end;
run;
PROC DATASETS library=WORK NoList NoDetails memtype=DATA;
 modify want_summary_Report_&amp;amp;checknm.;
  rename nr_&amp;amp;checknm._age    = age;
  rename nr_&amp;amp;checknm._height = height;
  rename nr_&amp;amp;checknm._weight = weight;
run; QUIT;
%MEND  profil;

%profil(checknm=nulls , checkop=EQ .);
%profil(checknm=zeros , checkop=EQ 0);
%profil(checknm=negw0 , checkop=LT 0);
%profil(checknm=posw0 , checkop=GT 0);

proc transpose data=want_summary_Report_nulls 
                out=want_summary_Report_nulls_tp(rename=(COL1=nr_nulls)); run;
proc transpose data=want_summary_Report_zeros 
                out=want_summary_Report_zeros_tp(rename=(COL1=nr_zeros)); run;
proc transpose data=want_summary_Report_negw0 
                out=want_summary_Report_negw0_tp(rename=(COL1=nr_negw0)); run;
proc transpose data=want_summary_Report_posw0 
                out=want_summary_Report_posw0_tp(rename=(COL1=nr_posw0)); run;

data profil;
 merge work.want_summary_Report_nulls_tp
       work.want_summary_Report_zeros_tp
	   work.want_summary_Report_negw0_tp
	   work.want_summary_Report_posw0_tp;
 by _NAME_;
 label _NAME_="Variable profiled";
run;

proc freq data=sashelp.class nlevels noprint;
 tables age    / out=work.distinct_levels_age;
 tables height / out=work.distinct_levels_height;
 tables weight / out=work.distinct_levels_weight;
run;
/* end of program */&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 12:17:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/m-p/929721#M83481</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2024-05-26T12:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: nr_null nr_zero,nr_POS,nr_NEG for each numeric var</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/m-p/929732#M83482</link>
      <description>&lt;P&gt;You could use the SIGN() function to convert your values into the four categories.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or you could define a format.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
 value sign low-&amp;lt;0 = 'Negative'
       0 = 'Zero'
       0&amp;lt;-high = 'Positive'
       other = 'Missing'
 ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have the format you could use it with PROC FREQ for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have;
  tables _numeric_ / missing list ;
  format _numeric_ sign.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could work a little harder and make a prettier output by using PROC SUMMARY and PROC TRANSPOSE.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have chartype completetypes;
 ways 1;
 class _numeric_ / missing preloadfmt;
 format _numeric_ sign.;
 output out=counts;
run;

data summary ;
  length name $32 ;
  set counts ;
  array vars _numeric_;
  index=indexc(_type_,'1');
  name=vname(vars[index]);
  sign=vvalue(vars[index]);
  count=_freq_;
  keep name sign count;
run;

proc transpose data=summary out=want(drop=_name_) ;
  by name notsorted;
  id sign;
  var count;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Let's make some sample data:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  array vars var1-var4 ;
  do row=1 to 10;
    do col=1 to dim(vars);
      select(rand('integer',4));
        when(1) vars[col]=.;
        when(2) vars[col]=-1;
        when(3) vars[col]=0;
        when(4) vars[col]=1;
        otherwise;
      end;
    end;
    output;
  end;
  drop row col;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So those two outputs would look something like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1716737631545.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96775i1A43D9CA5474A0E7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_0-1716737631545.png" alt="Tom_0-1716737631545.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_1-1716737650133.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/96776i71B2716D5A22AB9B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Tom_1-1716737650133.png" alt="Tom_1-1716737650133.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 26 May 2024 15:38:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/nr-null-nr-zero-nr-POS-nr-NEG-for-each-numeric-var/m-p/929732#M83482</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-05-26T15:38:58Z</dc:date>
    </item>
  </channel>
</rss>

