<?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: How to replace all previous values in a variable if a specific condition is met in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881424#M348280</link>
    <description>&lt;P&gt;So, before I go ahead and suggest a method, could there be -88 or -89 or -90 or ...&lt;/P&gt;
&lt;P&gt;in a column that is NOT gong to trigger this? Is this because (I have actually seen similar things) the -87 indicates some sort of special value? Can we just search for columns whose MINIMUM value is -87?&lt;/P&gt;</description>
    <pubDate>Mon, 19 Jun 2023 18:03:17 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2023-06-19T18:03:17Z</dc:date>
    <item>
      <title>How to replace all previous values in a variable if a specific condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881423#M348279</link>
      <description>&lt;P&gt;Hello! I am a beginner SAS programmer and I am trying to update one of my datasets.&amp;nbsp; I am trying to write code that will instruct SAS to search through a specific range of variables (Var1-Var200) in a dataset and look for a specific value (-87). If SAS finds that value present anywhere in that column, I want all the observations in that specific column to be replaced with that specified value. If possible, I would also like SAS to output a list of all the variables that were affected/updated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current dataset looks like this:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;Var1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Var2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Var3&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Var4&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amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried using ARRAY and the FIND function to loop through the list of variables and update, but I don't know how to code it to update previous entries/rows of the dataset.&amp;nbsp; I am also unsure how to write code that will output a list of the variables that were changed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;array v Var1-Var200;&lt;BR /&gt;do i=1 to dim(v);&lt;BR /&gt;if find(v(i), '-87') ge 1 then v(i)='-87';&lt;BR /&gt;end;&lt;BR /&gt;drop i;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I appreciate any and all feedback! Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 17:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881423#M348279</guid>
      <dc:creator>BlakeDG</dc:creator>
      <dc:date>2023-06-19T17:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace all previous values in a variable if a specific condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881424#M348280</link>
      <description>&lt;P&gt;So, before I go ahead and suggest a method, could there be -88 or -89 or -90 or ...&lt;/P&gt;
&lt;P&gt;in a column that is NOT gong to trigger this? Is this because (I have actually seen similar things) the -87 indicates some sort of special value? Can we just search for columns whose MINIMUM value is -87?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 18:03:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881424#M348280</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-19T18:03:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace all previous values in a variable if a specific condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881426#M348281</link>
      <description>No there won't be a -88, -89 etc. and Yes -87 indicates a special value and -87 would be the lowest possible value in this dataset</description>
      <pubDate>Mon, 19 Jun 2023 18:08:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881426#M348281</guid>
      <dc:creator>BlakeDG</dc:creator>
      <dc:date>2023-06-19T18:08:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace all previous values in a variable if a specific condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881427#M348282</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
proc summary data=have;
    var var1-var200;
    output out=_minimums_ min=min1-min200;
run;
data want;
    if _n_=1 then set _minimums_;
    set have;
    array v var1-var200;
    array m min1-min200;
    do i=1 to dim(v);
        if m(i)=-87 then v(i)=-87;
    end; 
    drop min1-min200 _type_ _freq_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Would it make even more sense (it might in some situations) to replace the -87 with a SAS missing value?&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 18:13:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881427#M348282</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-19T18:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace all previous values in a variable if a specific condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881430#M348283</link>
      <description>That did the trick! Thank you SO much! Is there any way to also create a list in like a "proc print-like" output of the variables that were affected?&lt;BR /&gt;&lt;BR /&gt;Appreciate all the help!</description>
      <pubDate>Mon, 19 Jun 2023 18:21:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881430#M348283</guid>
      <dc:creator>BlakeDG</dc:creator>
      <dc:date>2023-06-19T18:21:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace all previous values in a variable if a specific condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881433#M348284</link>
      <description>&lt;P&gt;Data set named _MINIMUMS_ has that information. You can print it any way you want.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 18:26:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881433#M348284</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-06-19T18:26:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to replace all previous values in a variable if a specific condition is met</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881435#M348285</link>
      <description>&lt;P&gt;I see that now. Thanks so much!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Jun 2023 18:30:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-replace-all-previous-values-in-a-variable-if-a-specific/m-p/881435#M348285</guid>
      <dc:creator>BlakeDG</dc:creator>
      <dc:date>2023-06-19T18:30:40Z</dc:date>
    </item>
  </channel>
</rss>

