<?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: Replace values from two variables into one in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-values-from-two-variables-into-one/m-p/685980#M208096</link>
    <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length Var_X Var_Y $10;
  input Var_X Var_Y;
cards;
1 1          
30 .
05 5           
2017-09-14 21076 
;run;

options datestyle=ymd;
data want;
  set have;
  length Varnew1 Varnew2 $10;
  if Var_X ne '' and Var_Y ne '' and Var_X ne Var_Y then do;
    if input(Var_Y,10.)=input(Var_X,?? anydtdte10.) then
      Varnew2=Var_Y;
    else if input(Var_Y,10.)=input(Var_X,10.) then
      Varnew1=Var_Y;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I added the OPTIONS DATESTYLE=YMD because some dates, e.g. 2017-09-08 can be ambigous.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 23 Sep 2020 09:28:11 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-09-23T09:28:11Z</dc:date>
    <item>
      <title>Replace values from two variables into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-values-from-two-variables-into-one/m-p/685979#M208095</link>
      <description>&lt;P&gt;Hello Community,&lt;/P&gt;&lt;P&gt;Question from a noob.&lt;/P&gt;&lt;P&gt;I have two variables that need to be compared. Variable x is the old variable and variable y the new one.&amp;nbsp;&lt;BR /&gt;The values in variable x partly have a leading zero and a different date format than the values in variable y. Other values may be ok.&amp;nbsp;&lt;BR /&gt;I created two new variables. Varnew1 holds all formatted&amp;nbsp; values with a leading zero. Varnew2 holds all formatted new date values. I used tranwrd.&amp;nbsp;&lt;BR /&gt;Is it now possible to replace the new values into Var x so that i can compare var x and var y?&lt;BR /&gt;Example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Var x&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Var y&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Varnew1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Varnew2&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;30&lt;/P&gt;&lt;P&gt;05&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;5&amp;nbsp;&lt;/P&gt;&lt;P&gt;2017-09-14&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21076&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;21076&lt;/P&gt;&lt;P&gt;...&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, 23 Sep 2020 08:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-values-from-two-variables-into-one/m-p/685979#M208095</guid>
      <dc:creator>drfzLee</dc:creator>
      <dc:date>2020-09-23T08:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Replace values from two variables into one</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-values-from-two-variables-into-one/m-p/685980#M208096</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  length Var_X Var_Y $10;
  input Var_X Var_Y;
cards;
1 1          
30 .
05 5           
2017-09-14 21076 
;run;

options datestyle=ymd;
data want;
  set have;
  length Varnew1 Varnew2 $10;
  if Var_X ne '' and Var_Y ne '' and Var_X ne Var_Y then do;
    if input(Var_Y,10.)=input(Var_X,?? anydtdte10.) then
      Varnew2=Var_Y;
    else if input(Var_Y,10.)=input(Var_X,10.) then
      Varnew1=Var_Y;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I added the OPTIONS DATESTYLE=YMD because some dates, e.g. 2017-09-08 can be ambigous.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Sep 2020 09:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-values-from-two-variables-into-one/m-p/685980#M208096</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-09-23T09:28:11Z</dc:date>
    </item>
  </channel>
</rss>

