<?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: Do loop for multiple variables with different dimensions in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279532#M7917</link>
    <description>&lt;P&gt;For this operation you don't need to iterate over the array to fill the missing values. &amp;nbsp;You can use CALL STDIZE to poke missing values with the mean. &amp;nbsp;My example uses 2 output statements to show before and after values of array A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data stdize;
   array a{5];
   input a[*];
   output;
   if nmiss(of a[*]) lt 3 then do;
      mean=mean(of a[*]);
      call stdize('none','missing=',mean,of a[*]);
      output;
      end;
   cards;
1 . 3 4 5
1 3 4 . .
10 . . . 20
;;;;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3719i32C61819C9F3EECB/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jun 2016 19:21:15 GMT</pubDate>
    <dc:creator>data_null__</dc:creator>
    <dc:date>2016-06-22T19:21:15Z</dc:date>
    <item>
      <title>Do loop for multiple variables with different dimensions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279418#M7914</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My question might be addressed somewhere here. I need to run "Do loop" for multiple variables with different dimensions. How can I do it within one data statement?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Specifically, I have the survey data with two measurments A and B. A includes items a1-a5, and B includes items B1-B3. If one respondent has less than half items per measurement are missing, the missing data is replaced by the mean values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I started my code like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;set data have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do i=1 to vardim;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if nmiss(of a1-a5)&amp;lt;3 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if a&amp;amp;i=. then a&amp;amp;i=mean(of a1-a5);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if nmiss(of b1-b3)&amp;lt;2 then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if b&amp;amp;i=.&amp;nbsp; then b&amp;amp;i=mean(of b1-b3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Could anyone help me correct it?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 16:57:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279418#M7914</guid>
      <dc:creator>lizzy28</dc:creator>
      <dc:date>2016-06-22T16:57:34Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop for multiple variables with different dimensions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279435#M7915</link>
      <description>&lt;P&gt;Seems like you're looking for the ARRAY statement. How about this (somewhat untested):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;set data have;

    array a_arr a1-a5;
    array b_arr b1-b3;

    do i=1 to dim(a_arr);
        if nmiss(of a1-a5)&amp;lt;3 then do;
            if a_arr[i]=. then a_arr[i]=mean(of a1-a5);
        end;
    end;

    do i=1 to dim(b_arr);
        if nmiss(of b1-b3)&amp;lt;2 then do;
            if b_arr[i]=.  then b_arr[i]=mean(of b1-b3);
        end;
    end;

run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may want to exhange the do loop with the if statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;...
    if nmiss(of b1-b3)&amp;lt;2 then do;
        do i=1 to dim(b_arr);
            if b_arr[i]=.  then b_arr[i]=mean(of b1-b3);
        end;
    end;
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 17:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279435#M7915</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-06-22T17:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop for multiple variables with different dimensions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279452#M7916</link>
      <description>&lt;P&gt;When you want to process several variables in the same way, the usual tool for the job is an ARRAY.&amp;nbsp; Here is one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;array a {5};&lt;/P&gt;
&lt;P&gt;array b {3};&lt;/P&gt;
&lt;P&gt;a_replacement = mean(of a1-a5);&lt;/P&gt;
&lt;P&gt;b_replacement = mean(of b1-b3);&lt;/P&gt;
&lt;P&gt;if nmiss(of a1-a5) &amp;lt; 3 then do _n_=1 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if a{_n_} = . then a{_n_} = a_replacement;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;if nmiss(of b1-b3)=1 then do _n_=1 to 5;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if b{_n_}=. then b{_n_} = b_replacement;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop a_replacement b_replacement;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 17:40:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279452#M7916</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-22T17:40:24Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop for multiple variables with different dimensions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279532#M7917</link>
      <description>&lt;P&gt;For this operation you don't need to iterate over the array to fill the missing values. &amp;nbsp;You can use CALL STDIZE to poke missing values with the mean. &amp;nbsp;My example uses 2 output statements to show before and after values of array A.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data stdize;
   array a{5];
   input a[*];
   output;
   if nmiss(of a[*]) lt 3 then do;
      mean=mean(of a[*]);
      call stdize('none','missing=',mean,of a[*]);
      output;
      end;
   cards;
1 . 3 4 5
1 3 4 . .
10 . . . 20
;;;;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/3719i32C61819C9F3EECB/image-size/original?v=v2&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 19:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279532#M7917</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-06-22T19:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop for multiple variables with different dimensions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279564#M7919</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52727"&gt;@lizzy28&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Specifically, I have the survey data with two measurements&amp;nbsp;A and B. A includes items a1-a5, and B includes items B1-B3. If one respondent has less than half items per measurement are missing, the missing data is replaced by the mean values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is a strange requirement. If you have few variable missing, just leave missing. But if you have a lot missing, use the little that is available to impute all missing values?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would resort to imputation when missing values are scarce.&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 20:37:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279564#M7919</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-22T20:37:28Z</dc:date>
    </item>
    <item>
      <title>Re: Do loop for multiple variables with different dimensions</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279569#M7920</link>
      <description>&lt;P&gt;Thank, PG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought about imputation, but my coworker team decided not to do something complicated.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 21:36:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Do-loop-for-multiple-variables-with-different-dimensions/m-p/279569#M7920</guid>
      <dc:creator>lizzy28</dc:creator>
      <dc:date>2016-06-22T21:36:04Z</dc:date>
    </item>
  </channel>
</rss>

