<?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: String replacement using reference values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/String-replacement-using-reference-values/m-p/913739#M360117</link>
    <description>&lt;P&gt;Here one way that should work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id var1 $ var2 $ var3 $;
  datalines;
1 * 1.2 *
2 * 3.7 0.3
3 0.7 * 2
4 4.9 4.0 1.8
;

proc format;
  invalue var1f
    '*' = 2
    other=[best32.]
    ;
  invalue var2f
    '*' = 4.5
    other=[best32.]
    ;
  invalue var3f
    '*' = 17
    other=[best32.]
    ;
run;

data want(drop=_:);
  set have(rename=(var1=_var1 var2=_var2 var3=_var3));
  var1=input(_var1,?? var1f.);
  var2=input(_var2,?? var2f.);
  var3=input(_var3,?? var3f.);
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1706696474499.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93092i3D618956D82580CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1706696474499.png" alt="Patrick_0-1706696474499.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 31 Jan 2024 10:24:04 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2024-01-31T10:24:04Z</dc:date>
    <item>
      <title>String replacement using reference values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-replacement-using-reference-values/m-p/913733#M360115</link>
      <description>&lt;P&gt;I have a dataset with one id column and three character variables:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data have;
    input id var1 $ var2 $ var3 $;
    datalines;
    1 * 1.2 *
    2 * 3.7 0.3
    3 0.7 * 2
    4 4.9 4.0 1.8
    ;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For each of the character variable, I want to replace the '*' character with a string that is specific to the variable.&lt;/P&gt;&lt;P&gt;For example, in var1 '*' would be replace by '2', then in var2 '*' would be replaced by '4.5', etc...&lt;/P&gt;&lt;P&gt;And then I would like to turn these variables to numeric.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way of doing this using a "reference" table with the replacement values&amp;nbsp; ?&lt;/P&gt;&lt;P&gt;For example with a table like this one:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data reference;
    input var1 $ var2 $ var3 $;
    datalines;
	2 4.5 17
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 31 Jan 2024 09:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-replacement-using-reference-values/m-p/913733#M360115</guid>
      <dc:creator>ABohyn</dc:creator>
      <dc:date>2024-01-31T09:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: String replacement using reference values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-replacement-using-reference-values/m-p/913735#M360116</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/460538"&gt;@ABohyn&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think a reference table with numeric variables like this&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data reference;
input r1-r3;
datalines;
2 4.5 17
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;would be more convenient:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(rename=(nvar1-nvar3=var1-var3));
set have;
if _n_=1 then set reference;
array var[3];
array nvar[3];
array r[3];
do i=1 to dim(var);
  nvar[i]=coalesce(input(var[i], ?? 32.),r[i]);
end;
drop i r1-r3 var1-var3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This would perform the character-to-numeric conversion and replace all non-numeric values of &lt;FONT face="courier new,courier"&gt;var1-var3&lt;/FONT&gt; with the corresponding&amp;nbsp;&lt;SPAN&gt;replacement values.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 09:52:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-replacement-using-reference-values/m-p/913735#M360116</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2024-01-31T09:52:07Z</dc:date>
    </item>
    <item>
      <title>Re: String replacement using reference values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/String-replacement-using-reference-values/m-p/913739#M360117</link>
      <description>&lt;P&gt;Here one way that should work&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input id var1 $ var2 $ var3 $;
  datalines;
1 * 1.2 *
2 * 3.7 0.3
3 0.7 * 2
4 4.9 4.0 1.8
;

proc format;
  invalue var1f
    '*' = 2
    other=[best32.]
    ;
  invalue var2f
    '*' = 4.5
    other=[best32.]
    ;
  invalue var3f
    '*' = 17
    other=[best32.]
    ;
run;

data want(drop=_:);
  set have(rename=(var1=_var1 var2=_var2 var3=_var3));
  var1=input(_var1,?? var1f.);
  var2=input(_var2,?? var2f.);
  var3=input(_var3,?? var3f.);
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1706696474499.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/93092i3D618956D82580CF/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1706696474499.png" alt="Patrick_0-1706696474499.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Jan 2024 10:24:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/String-replacement-using-reference-values/m-p/913739#M360117</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-01-31T10:24:04Z</dc:date>
    </item>
  </channel>
</rss>

