<?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: write macro or automate process in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863208#M341002</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173636"&gt;@Satori&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to do it in a custom way you can automate it with a macro. Simple (and imperfect) example below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x y z;
datalines ;
1 2 3
. 1 3
1 . 4
4 3 .
3 4 .
;

%macro removeNulls(indat);
ods output variables=variables;
proc contents data=&amp;amp;indat;run;

data vars;
set variables;
idx+1;
keep idx variable;
run;

proc sql noprint; select max(idx) into :varmax from vars;quit;

%do i=1 %to &amp;amp;varmax.;

proc sql noprint; select variable into :curvar from vars where idx=&amp;amp;i.;quit;

data &amp;amp;indat;
set &amp;amp;indat;
if missing(&amp;amp;curvar.) then delete;
if &amp;amp;curvar. &amp;lt; 0 then delete;
run;

%end;

%mend;

%removeNulls(have);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 Mar 2023 14:52:18 GMT</pubDate>
    <dc:creator>HarrySnart</dc:creator>
    <dc:date>2023-03-09T14:52:18Z</dc:date>
    <item>
      <title>write macro or automate process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863191#M340993</link>
      <description>&lt;P&gt;I have this code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want1; set have; if missing(assets) then delete; if assets&amp;lt;0 then delete;
proc format; value missfmt .,0 ='Missing' other='Not Missing'; proc freq data=want1; format _NUMERIC_ missfmt.;
	tables _NUMERIC_ / missing missprint nocum;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;After consulting the proc freq results I see that, after assets, fixed_assets is the next variable with more non missing observations so I run the following code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want2; set want1; if missing(fixed_assets) then delete; if fixed_assets&amp;lt;0 then delete;
proc format; value missfmt .,0 ='Missing' other='Not Missing'; proc freq data=want2; format _NUMERIC_ missfmt.;
	tables _NUMERIC_ / missing missprint nocum;&lt;/CODE&gt;&lt;CODE class=""&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;after I see from proc freq that the next variable is sales so I run the code again:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data want3; set want2; if missing(sales) then delete;
proc format; value missfmt .,0 ='Missing' other='Not Missing'; proc freq data=want3; format _NUMERIC_ missfmt.;
	tables _NUMERIC_ / missing missprint nocum;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have list of 50 variables to go through, so I would like to automate this process and not have it done manually. How can I achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 14:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863191#M340993</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-03-09T14:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: write macro or automate process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863200#M340998</link>
      <description>&lt;P&gt;We have already discussed this with you in your &lt;A href="https://communities.sas.com/t5/SAS-Programming/dynamic-counting-of-non-missing-observations/m-p/858908#M339364" target="_self"&gt;earlier threads&lt;/A&gt;, in which &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt; made the valuable suggestion to use the Missing Pattern report from PROC MI; and in which I also made suggestions regarding fitting models when there is lots of missing data. What is wrong with using those suggestions?&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 14:45:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863200#M340998</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-03-09T14:45:49Z</dc:date>
    </item>
    <item>
      <title>Re: write macro or automate process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863206#M341001</link>
      <description>My only goal is to learn how to automate this process, not so much on the appropriate way of dealing with missing data. The suggestions on earlier threads focused on the best ways of dealing with missing data so I didn't find them helpful for my purpose.</description>
      <pubDate>Thu, 09 Mar 2023 14:47:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863206#M341001</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-03-09T14:47:47Z</dc:date>
    </item>
    <item>
      <title>Re: write macro or automate process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863208#M341002</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173636"&gt;@Satori&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you need to do it in a custom way you can automate it with a macro. Simple (and imperfect) example below&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x y z;
datalines ;
1 2 3
. 1 3
1 . 4
4 3 .
3 4 .
;

%macro removeNulls(indat);
ods output variables=variables;
proc contents data=&amp;amp;indat;run;

data vars;
set variables;
idx+1;
keep idx variable;
run;

proc sql noprint; select max(idx) into :varmax from vars;quit;

%do i=1 %to &amp;amp;varmax.;

proc sql noprint; select variable into :curvar from vars where idx=&amp;amp;i.;quit;

data &amp;amp;indat;
set &amp;amp;indat;
if missing(&amp;amp;curvar.) then delete;
if &amp;amp;curvar. &amp;lt; 0 then delete;
run;

%end;

%mend;

%removeNulls(have);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 Mar 2023 14:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863208#M341002</guid>
      <dc:creator>HarrySnart</dc:creator>
      <dc:date>2023-03-09T14:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: write macro or automate process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863274#M341020</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/173636"&gt;@Satori&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;My only goal is to learn how to automate this process, not so much on the appropriate way of dealing with missing data. The suggestions on earlier threads focused on the best ways of dealing with missing data so I didn't find them helpful for my purpose.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I posted a macro in that thread which tried to implement your logic:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/dynamic-counting-of-non-missing-observations/m-p/858858/highlight/true#M339341" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/dynamic-counting-of-non-missing-observations/m-p/858858/highlight/true#M339341&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did that macro not work for your need?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Mar 2023 20:05:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863274#M341020</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2023-03-09T20:05:28Z</dc:date>
    </item>
    <item>
      <title>Re: write macro or automate process</title>
      <link>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863604#M341124</link>
      <description>I was not able to make it work. Not very good at writing macros. Still learning.</description>
      <pubDate>Sat, 11 Mar 2023 16:09:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/write-macro-or-automate-process/m-p/863604#M341124</guid>
      <dc:creator>Satori</dc:creator>
      <dc:date>2023-03-11T16:09:42Z</dc:date>
    </item>
  </channel>
</rss>

