<?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 Change Multiple variables with different values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-Multiple-variables-with-different-values/m-p/598874#M172765</link>
    <description>&lt;P&gt;I have about 29 character variables in a dataset that need to be changed depending on which column it is in.&amp;nbsp; I know how to list all the IF statement like below, but would like to do it different as it will help in similar projects in the future.&amp;nbsp; So if the values are not equal to zero then I need to change the values depending on which column it is in. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;/P&gt;&lt;P&gt;LENGTH F1 $2 F2 $2;&lt;/P&gt;&lt;P&gt;INPUT F1 $ F2 $&lt;/P&gt;&lt;P&gt;DATALINES;&lt;/P&gt;&lt;P&gt;00 00&lt;/P&gt;&lt;P&gt;10 12&lt;/P&gt;&lt;P&gt;00 12&lt;/P&gt;&lt;P&gt;10 00&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&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;IF FR1 ^= '00' THEN FR1 = '05';&lt;/P&gt;&lt;P&gt;IF FR2 ^= '00' THEN FR2 = '36';&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;</description>
    <pubDate>Thu, 24 Oct 2019 00:27:39 GMT</pubDate>
    <dc:creator>cjoneckis10</dc:creator>
    <dc:date>2019-10-24T00:27:39Z</dc:date>
    <item>
      <title>Change Multiple variables with different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Multiple-variables-with-different-values/m-p/598874#M172765</link>
      <description>&lt;P&gt;I have about 29 character variables in a dataset that need to be changed depending on which column it is in.&amp;nbsp; I know how to list all the IF statement like below, but would like to do it different as it will help in similar projects in the future.&amp;nbsp; So if the values are not equal to zero then I need to change the values depending on which column it is in. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;DATA HAVE;&lt;/P&gt;&lt;P&gt;LENGTH F1 $2 F2 $2;&lt;/P&gt;&lt;P&gt;INPUT F1 $ F2 $&lt;/P&gt;&lt;P&gt;DATALINES;&lt;/P&gt;&lt;P&gt;00 00&lt;/P&gt;&lt;P&gt;10 12&lt;/P&gt;&lt;P&gt;00 12&lt;/P&gt;&lt;P&gt;10 00&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&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;IF FR1 ^= '00' THEN FR1 = '05';&lt;/P&gt;&lt;P&gt;IF FR2 ^= '00' THEN FR2 = '36';&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 00:27:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Multiple-variables-with-different-values/m-p/598874#M172765</guid>
      <dc:creator>cjoneckis10</dc:creator>
      <dc:date>2019-10-24T00:27:39Z</dc:date>
    </item>
    <item>
      <title>Re: Change Multiple variables with different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Multiple-variables-with-different-values/m-p/598887#M172774</link>
      <description>&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;         
  set HAVE;
  array NEW [2] $2 _temporary_ ('05','36');
  array COL [2] F1-F2;
  do i =1 to 2;
    if COL[I]='00' then COL[I]=NEW[I];
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 01:43:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Multiple-variables-with-different-values/m-p/598887#M172774</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-24T01:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: Change Multiple variables with different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Multiple-variables-with-different-values/m-p/598961#M172814</link>
      <description>&lt;P&gt;Thank you!&amp;nbsp; that works&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 10:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Multiple-variables-with-different-values/m-p/598961#M172814</guid>
      <dc:creator>cjoneckis10</dc:creator>
      <dc:date>2019-10-24T10:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Change Multiple variables with different values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-Multiple-variables-with-different-values/m-p/599112#M172877</link>
      <description>&lt;P&gt;Another approach is to move the If/then logic to a format.&lt;/P&gt;
&lt;PRE&gt;Proc format library=work;
value $F1_
'00' = '00'
other= '05'
;
value $F2_
'00' = '00'
other= '36'
;

DATA HAVE;
LENGTH F1 $2 F2 $2;
INPUT F1 $ F2 $ ;
DATALINES;
00 00
10 12
00 12
10 00
;
RUN;
 
DATA WANT;
SET HAVE;
   f1 = put(f1,$f1_.);
   f2 = put(f2,$f2_.);
RUN;

/* or use the format without changing values*/
Proc print data=have;
format f1 $f1_. f2 $f2_.;
run;

&lt;/PRE&gt;
&lt;P&gt;Format names can't end in a digit so I used the _.&lt;/P&gt;
&lt;P&gt;This has some flexibility because you said "it different as it will help in similar projects in the future.".&lt;/P&gt;
&lt;P&gt;The values assigned by a format can be used by almost any analysis, graphing or reporting procedure. So if you have multiple values that need the '00' or '36' coding you don't really need to modify the data sets but can just apply the format when needed.&lt;/P&gt;
&lt;P&gt;Or change the coding for any one variable to pick different coding as needed. Suppose your F1 variable would in some case (given more values than '00' and '10' ) like to have 3 report groups. If you actually change the value then you would have to retrace the to an earlier form of the data set before doing the recoding. But if you leave the original values alone then using a different format on the original value uses the variable as desired.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Oct 2019 17:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-Multiple-variables-with-different-values/m-p/599112#M172877</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-10-24T17:43:09Z</dc:date>
    </item>
  </channel>
</rss>

