<?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: Help with changing multiple variables to the same values to a certain point in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Help-with-changing-multiple-variables-to-the-same-values-to-a/m-p/489042#M127563</link>
    <description>&lt;P&gt;You use an array without definition (iscert) so it isn't quite clear what you are attempting in the code.&lt;/P&gt;
&lt;P&gt;I am guessing this may give you a start.&lt;/P&gt;
&lt;PRE&gt;data combine;
input event_year;
datalines;
0
3
18
25
;
run;

data newcombine;
   set combine;
   array metreq (0:29) metreq_0-metreq_29 ;
   /*initialize array to 0*/
   do i=0 to 29;
      metreq[i] = 0;
   end;
   do i = event_year to (min(29, event_year+10));
      metreq[i] = 1;
   end;
run;
&lt;/PRE&gt;
&lt;P&gt;The use of coding structures like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data combine;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set combine;&lt;/P&gt;
&lt;P&gt;&amp;lt;any other code&amp;gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;has a strong likelihood of causing either lost data or erroneous values as you rerun the same code with modifications. Each run completely replaces the existing data set.&lt;/P&gt;
&lt;P&gt;Run the second data step below 3 times without running the first data step and see what happens.&lt;/P&gt;
&lt;PRE&gt;data junk;
   x= 3;
run;

data junk;
   set junk;
   x= x-1;
   if x;
run;&lt;/PRE&gt;
&lt;P&gt;Any modification to an existing variable is dangerous. And you may end up with many variables with intention.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Aug 2018 20:39:17 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-08-22T20:39:17Z</dc:date>
    <item>
      <title>Help with changing multiple variables to the same values to a certain point</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-changing-multiple-variables-to-the-same-values-to-a/m-p/489036#M127558</link>
      <description>&lt;P&gt;I need help with a problem I'm trying to code. I want to assume that a specific time is limited to 30 years. I then want to say if an event happened within those 30 years, a person is receives a flag showing they met requirements for the next 10 years. I plan to do this by indicating at what year the event happened (with a variable called event_year) and then I want a group of flags (met_req0-metreq_29) to be turned from 0 to 1 to indicate the 10 year period they&amp;nbsp;met their requirements. I tried the following code, but&amp;nbsp;1) I&amp;nbsp;think it's clunky and 2)&amp;nbsp;I get an error because later years (e.g., event_year = 20), it tries to flag variables that don't exist. For example metreq_29 is as far as my array variables go and this code attempts to manipulate variable metreq_20 - metreq_30, the latter of which doesn't exist. Any ideas on the best way to do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="5"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="5"&gt; combine;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="5"&gt;set&lt;/FONT&gt;&lt;FONT face="Courier New" size="5"&gt; combine;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="5"&gt;array&lt;/FONT&gt;&lt;FONT face="Courier New" size="5"&gt;&amp;nbsp;metreq (*) metreq_0-metreq_29;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="5"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="5"&gt; i = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;0&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="5"&gt;to&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;29&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="5"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="5"&gt; event_year = i &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="5"&gt;then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="5"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;3&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;9&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="5"&gt;iscert[i+&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;10&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;] = &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="5"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="5"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="5"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="5"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 20:19:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-changing-multiple-variables-to-the-same-values-to-a/m-p/489036#M127558</guid>
      <dc:creator>whitknee48</dc:creator>
      <dc:date>2018-08-22T20:19:01Z</dc:date>
    </item>
    <item>
      <title>Re: Help with changing multiple variables to the same values to a certain point</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Help-with-changing-multiple-variables-to-the-same-values-to-a/m-p/489042#M127563</link>
      <description>&lt;P&gt;You use an array without definition (iscert) so it isn't quite clear what you are attempting in the code.&lt;/P&gt;
&lt;P&gt;I am guessing this may give you a start.&lt;/P&gt;
&lt;PRE&gt;data combine;
input event_year;
datalines;
0
3
18
25
;
run;

data newcombine;
   set combine;
   array metreq (0:29) metreq_0-metreq_29 ;
   /*initialize array to 0*/
   do i=0 to 29;
      metreq[i] = 0;
   end;
   do i = event_year to (min(29, event_year+10));
      metreq[i] = 1;
   end;
run;
&lt;/PRE&gt;
&lt;P&gt;The use of coding structures like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data combine;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set combine;&lt;/P&gt;
&lt;P&gt;&amp;lt;any other code&amp;gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;has a strong likelihood of causing either lost data or erroneous values as you rerun the same code with modifications. Each run completely replaces the existing data set.&lt;/P&gt;
&lt;P&gt;Run the second data step below 3 times without running the first data step and see what happens.&lt;/P&gt;
&lt;PRE&gt;data junk;
   x= 3;
run;

data junk;
   set junk;
   x= x-1;
   if x;
run;&lt;/PRE&gt;
&lt;P&gt;Any modification to an existing variable is dangerous. And you may end up with many variables with intention.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Aug 2018 20:39:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Help-with-changing-multiple-variables-to-the-same-values-to-a/m-p/489042#M127563</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-22T20:39:17Z</dc:date>
    </item>
  </channel>
</rss>

