<?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 a value with another in a dataset using a extern file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-value-with-another-in-a-dataset-using-a-extern-file/m-p/765903#M242651</link>
    <description>&lt;P&gt;how about this code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* sample dataset */
data have;
  do XYZ=98000 to 200000;
    output;
  end;
run;

/* create sample txt file to explain */
filename txt temp;
data _null_;
  file txt;
  put '98765;12345';
  put '98764;12345';
  put '98763;12346';
  put '198763;12346';
run;

*filename txt 'C:\data\project\qwert.txt'; /* &amp;lt;- In your environment. */

data QWERT;
  infile txt dlm=';';
  length xyz newnum 8;
  input xyz newnum;
run;
filename txt;
proc sort;
  by xyz;
run;
data want;
  merge have qwert(in=inB);
  by xyz;
  if inB then xyz=newnum;
  drop newnum;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Sep 2021 17:37:47 GMT</pubDate>
    <dc:creator>japelin</dc:creator>
    <dc:date>2021-09-03T17:37:47Z</dc:date>
    <item>
      <title>Replace a value with another in a dataset using a extern file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-value-with-another-in-a-dataset-using-a-extern-file/m-p/765896#M242646</link>
      <description>&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b"&gt;&lt;SPAN&gt;I have a dataset with a lot of observations. A variable of observation is a number. I want to replace this number with another one. Which number is the correct replacement is in a separate file (which can have chances over the years). My previous solution is that I wrote every possible substitute in the code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;if XYZ = 98765 then
  do XYZ = 12345;
end;

if XYZ = 98764 then
  do XYZ = 12345;
end;

if XYZ = 98763 then
  do XYZ = 12346;
end;&lt;/PRE&gt;&lt;P&gt;The datafine is *.txt and looks like this:&lt;/P&gt;&lt;P&gt;98765;12345&lt;/P&gt;&lt;P&gt;98764;12345&lt;/P&gt;&lt;P&gt;98763;12346&lt;/P&gt;&lt;P&gt;198763;12346 and so on (yes, the first variable is some times 5 digits, sometime 6 digits. the second is allways 5 digits)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b"&gt;&lt;SPAN&gt;I would like a solution in which my program reads the * .txt file every time I start the program and replaces the specific value within the 150,000 observation. The program reads the dataset with:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;data QWERT;
	infile 'C:\data\project\qwert.txt' lrecl=410;
	input @20 XYZ 6.;
/* some other stuff happening that is not relevant for the challenge */
run;&lt;/PRE&gt;&lt;P&gt;I was thinking of some kind of loop while reading the file and than a replacement routine. But I dont really know how to start.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using SAS Enterpirse Guide 7.12 HF8 (German Version)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 17:05:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-value-with-another-in-a-dataset-using-a-extern-file/m-p/765896#M242646</guid>
      <dc:creator>Gedankenfee</dc:creator>
      <dc:date>2021-09-03T17:05:30Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a value with another in a dataset using a extern file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-value-with-another-in-a-dataset-using-a-extern-file/m-p/765897#M242647</link>
      <description>&lt;P&gt;Please show an full example - what you have as your original data set, what you have as your modification data set and what you want as your final output. Please create a small representative example of your actual data structure. &lt;BR /&gt;&lt;BR /&gt;Some options you can look into are UPDATE, MODIFY and COALESCE with a merge. If you'd like code examples please provide the information requested.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/396153"&gt;@Gedankenfee&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b"&gt;&lt;SPAN&gt;I have a dataset with a lot of observations. A variable of observation is a number. I want to replace this number with another one. Which number is the correct replacement is in a separate file (which can have chances over the years). My previous solution is that I wrote every possible substitute in the code:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;if XYZ = 98765 then
  do XYZ = 12345;
end;

if XYZ = 98764 then
  do XYZ = 12345;
end;

if XYZ = 98763 then
  do XYZ = 12346;
end;&lt;/PRE&gt;
&lt;P&gt;The datafine is *.txt and looks like this:&lt;/P&gt;
&lt;P&gt;98765;12345&lt;/P&gt;
&lt;P&gt;98764;12345&lt;/P&gt;
&lt;P&gt;98763;12346&lt;/P&gt;
&lt;P&gt;198763;12346 and so on (yes, the first variable is some times 5 digits, sometime 6 digits. the second is allways 5 digits)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="VIiyi"&gt;&lt;SPAN class="JLqJ4b"&gt;&lt;SPAN&gt;I would like a solution in which my program reads the * .txt file every time I start the program and replaces the specific value within the 150,000 observation. The program reads the dataset with:&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;data QWERT;
	infile 'C:\data\project\qwert.txt' lrecl=410;
	input @20 XYZ 6.;
/* some other stuff happening that is not relevant for the challenge */
run;&lt;/PRE&gt;
&lt;P&gt;I was thinking of some kind of loop while reading the file and than a replacement routine. But I dont really know how to start.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am using SAS Enterpirse Guide 7.12 HF8 (German Version)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 17:11:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-value-with-another-in-a-dataset-using-a-extern-file/m-p/765897#M242647</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-09-03T17:11:21Z</dc:date>
    </item>
    <item>
      <title>Re: Replace a value with another in a dataset using a extern file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replace-a-value-with-another-in-a-dataset-using-a-extern-file/m-p/765903#M242651</link>
      <description>&lt;P&gt;how about this code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* sample dataset */
data have;
  do XYZ=98000 to 200000;
    output;
  end;
run;

/* create sample txt file to explain */
filename txt temp;
data _null_;
  file txt;
  put '98765;12345';
  put '98764;12345';
  put '98763;12346';
  put '198763;12346';
run;

*filename txt 'C:\data\project\qwert.txt'; /* &amp;lt;- In your environment. */

data QWERT;
  infile txt dlm=';';
  length xyz newnum 8;
  input xyz newnum;
run;
filename txt;
proc sort;
  by xyz;
run;
data want;
  merge have qwert(in=inB);
  by xyz;
  if inB then xyz=newnum;
  drop newnum;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Sep 2021 17:37:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replace-a-value-with-another-in-a-dataset-using-a-extern-file/m-p/765903#M242651</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-09-03T17:37:47Z</dc:date>
    </item>
  </channel>
</rss>

