<?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: Repeat a process for multiple variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Repeat-a-process-for-multiple-variables/m-p/343035#M78692</link>
    <description>&lt;P&gt;I figured it out with the help of this &lt;A href="http://www.lexjansen.com/nesug/nesug05/pm/pm8.pdf" target="_self"&gt;article&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Array test(32) /*1-5(5) + 6-10(5) + 11-15(5) = 15
/*  1         2           3         4          5  */
prevar1_v1 prevar2_v1 prevar2_v1 prevar2_v1 prevar2_v1 /*n = 5*/
/*  6         7           8         9         10  */
prevar1_v2 prevar2_v2 prevar2_v2 prevar2_v2 prevar2_v2 /*n = 5*/
/* 11        12          13        14         15  */
prevar1_v2 prevar2_v2 prevar2_v2 prevar2_v2 prevar2_v2 /*n = 5*/;
Do i = 1 to 15;
if test in(0) then test{i} = . ; 
End; 

Do i = 6 to 15;
if test in(1) then test{i} = . ; 
End;

Do i = 11 to 15;
if test in(2) then test{i} = . ; 
End;&lt;/PRE&gt;</description>
    <pubDate>Tue, 21 Mar 2017 19:16:17 GMT</pubDate>
    <dc:creator>jckbnimble</dc:creator>
    <dc:date>2017-03-21T19:16:17Z</dc:date>
    <item>
      <title>Repeat a process for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-a-process-for-multiple-variables/m-p/342926#M78653</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to repeat a process for 15 variables and I normally due this just my copying and pasting the code several times. I was wondering if an array or a macro could do the same thing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have two things that I would like to make more 'compact"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;for variables &lt;STRONG&gt;pre_&lt;/STRONG&gt;var1-15&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1: make certain partions missing based on a conditional&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if test = 0 then pre_var1_v1 = .;&lt;BR /&gt;if test in(0,1) then pre_&lt;SPAN&gt;var1_&lt;/SPAN&gt;v2 = .;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;if test in(0,1) then pre_var1_v3 = .;&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;2: &amp;nbsp;If data is missing fill in with previous data&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;if var1_F = . and time &amp;lt;= 25 then var1_F = pre_var1_v1 ;&lt;/STRIKE&gt;&lt;BR /&gt;&lt;STRIKE&gt;if var1_F = . and time &amp;lt;= 25 then var1_F = pre_var1_v2 ;&lt;/STRIKE&gt;&lt;BR /&gt;&lt;STRIKE&gt;if var1_F = . and time &amp;lt;= 25 then var1_F = pre_var1_v3 ;&lt;/STRIKE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would be great,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;Jack&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;EDIT:&lt;/P&gt;&lt;P&gt;I have edited the above text in bold.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When the variable test is 0, I would like to make (&lt;SPAN&gt;pre_var1_v1 = .) &amp;nbsp;and when test = 0 or test = 1 then I would like to make (pre_var1_v2 = .). For the sake of simplicity, I took out the&amp;nbsp;pre_var1_v3 variable.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I took out the second part, I believe if I can get a start on how to build the macro/array in the first part, I can figure out how to code it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As per request, attached is the before/ after of the data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data have;&lt;BR /&gt;input id test time pre_var1_v1 pre_var1_v2 pre_var1_v3;&lt;BR /&gt;cards;&lt;BR /&gt;1 0 0 1.5 1.6 1.4&lt;BR /&gt;1 1 5 0.5 1.5 1.6&lt;BR /&gt;1 2 10 0.9 0.5 1.5&lt;BR /&gt;1 3 15 0.7 0.9 0.5&lt;BR /&gt;1 4 20 0.6 0.7 0.9&lt;BR /&gt;2 0 0 1.5 1.6 1.4&lt;BR /&gt;2 1 5 0.5 1.5 1.6&lt;BR /&gt;2 2 10 0.9 0.5 1.5&lt;BR /&gt;2 3 15 0.7 0.9 0.5&lt;BR /&gt;2 4 20 0.6 0.7 0.9&lt;BR /&gt;;;;;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;input id test time pre_var1_v1 pre_var1_v2;&lt;BR /&gt;cards;&lt;BR /&gt;1 0 0 . .&lt;BR /&gt;1 1 5 0.5 .&lt;BR /&gt;1 2 10 0.9 0.5&lt;BR /&gt;1 3 15 0.7 0.9&lt;BR /&gt;1 4 20 0.6 0.7&lt;BR /&gt;2 0 0 . .&lt;BR /&gt;2 1 5 0.5 .&lt;BR /&gt;2 2 10 0.9 0.5&lt;BR /&gt;2 3 15 0.7 0.9&lt;BR /&gt;2 4 20 0.6 0.7&lt;BR /&gt;;;;;;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 16:08:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-a-process-for-multiple-variables/m-p/342926#M78653</guid>
      <dc:creator>jckbnimble</dc:creator>
      <dc:date>2017-03-21T16:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat a process for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-a-process-for-multiple-variables/m-p/342942#M78663</link>
      <description>&lt;P&gt;You really need to supply some example data of your input data set and what the final result should be. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What to do if missing value is on the first row?&lt;/P&gt;
&lt;P&gt;What if time is missing? Missing is always less than 25 (or anything else for that matter) so confirm that is when you need to implement this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You say to do this for Var1-15 but then never mention where Var1 is used/considered.&lt;/P&gt;
&lt;P&gt;And this only makes sense if whatever pre_var_v1 and pre_var_v2 are missing. Is that your intent to go through a list of variables and assign the first non-missing value??&lt;/P&gt;
&lt;PRE&gt;if var1_F = . and time &amp;lt;= 25 then var1_F = pre_var1_v1 ;
if var1_F = . and time &amp;lt;= 25 then var1_F = pre_var1_v2 ;
if var1_F = . and time &amp;lt;= 25 then var1_F = pre_var1_v3 ;
&lt;/PRE&gt;
&lt;P&gt;It is not clear if your pre_var1_v1 etc variables even exist or not. So the example datastep generated by the above instructions will clear up all questions about your starting data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Mar 2017 14:41:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-a-process-for-multiple-variables/m-p/342942#M78663</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-21T14:41:02Z</dc:date>
    </item>
    <item>
      <title>Re: Repeat a process for multiple variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Repeat-a-process-for-multiple-variables/m-p/343035#M78692</link>
      <description>&lt;P&gt;I figured it out with the help of this &lt;A href="http://www.lexjansen.com/nesug/nesug05/pm/pm8.pdf" target="_self"&gt;article&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Array test(32) /*1-5(5) + 6-10(5) + 11-15(5) = 15
/*  1         2           3         4          5  */
prevar1_v1 prevar2_v1 prevar2_v1 prevar2_v1 prevar2_v1 /*n = 5*/
/*  6         7           8         9         10  */
prevar1_v2 prevar2_v2 prevar2_v2 prevar2_v2 prevar2_v2 /*n = 5*/
/* 11        12          13        14         15  */
prevar1_v2 prevar2_v2 prevar2_v2 prevar2_v2 prevar2_v2 /*n = 5*/;
Do i = 1 to 15;
if test in(0) then test{i} = . ; 
End; 

Do i = 6 to 15;
if test in(1) then test{i} = . ; 
End;

Do i = 11 to 15;
if test in(2) then test{i} = . ; 
End;&lt;/PRE&gt;</description>
      <pubDate>Tue, 21 Mar 2017 19:16:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Repeat-a-process-for-multiple-variables/m-p/343035#M78692</guid>
      <dc:creator>jckbnimble</dc:creator>
      <dc:date>2017-03-21T19:16:17Z</dc:date>
    </item>
  </channel>
</rss>

