<?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: Code that finds and replaces character value in a column in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623711#M19980</link>
    <description>&lt;P&gt;The "If-Then" statement worked for me.&amp;nbsp; I have an excel sheet with a column for the list of abbreviations and another column with the corresponding full name.&amp;nbsp; Is there syntax I can use to incorporate that file so that I don't have to enter in 100 county names?&amp;nbsp; &amp;nbsp;Alternatively, could I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname rabdata xlsx "/folders/myfolders/sasuser.v94/2019RabData_Raw.XLS.xlsx";&lt;/P&gt;&lt;P&gt;data newtable;&lt;BR /&gt;set rabdata.rab19;&lt;BR /&gt;If Animal_Address_County="FRA" then Animal_Address_County="FRANKLIN";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data newtable;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;infile countyname.xlsx;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input Animal_Address_County:$30.;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;FRAN, Franklin&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;A, Ash&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Lay, Layton;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Feb 2020 21:58:20 GMT</pubDate>
    <dc:creator>AJS1</dc:creator>
    <dc:date>2020-02-10T21:58:20Z</dc:date>
    <item>
      <title>Code that finds and replaces character value in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623657#M19969</link>
      <description>&lt;P&gt;I have a column named "County" that lists the abbreviations for each county.&amp;nbsp; I want to replace the county abbreviations with the full name but can't figure out how to do so (If-then, Macro....???).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have taken the SAS essentials 1 course but am still struggling with writing basic code.&amp;nbsp; Any suggestions on a reference that may be helpful?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 18:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623657#M19969</guid>
      <dc:creator>AJS1</dc:creator>
      <dc:date>2020-02-10T18:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Code that finds and replaces character value in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623662#M19972</link>
      <description>&lt;P&gt;Multiple ways&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. IF THEN like you mentioned. PG1 level.&lt;/P&gt;
&lt;P&gt;2. Using a format. PG2 level.&lt;/P&gt;
&lt;P&gt;3. Using a JOIN. SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I completed 1 an 2 for you. That should get you going. Depending on the number of unique values, i'd prefer one way over the other.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I had only a few countries and don't need to reuse the code i'd probably just use an if/then.&lt;/P&gt;
&lt;P&gt;If I need to use this functionality more often, or I have a large list of unique values, i'd use option 2 or 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*table with country abbreviations*/
data ctry;
	infile datalines;
	input Country:$3.;
	datalines;
US
GR
CA
;
run;


*************************************;
* IF THEN SOLUTION	(PG1 Level)     *;
*************************************;
data newtable;
	set ctry;
	if Country='US' then FullName = 'United States';
		else if Country='GR' then FullName='Greece';
		else if Country='CA' then FullName='Canada';
run;
/*You can change the FullName column to 'Country' if you want to overwrite the existing value*/


***************************************************;
* More Efficient Solution if want to reuse the    *;
* functionality, or you have a long country list  *;
* (PG2 Level Topics)                              *;
***************************************************;

/*Google to find a country abbreviations lookup table online. Probably find a csv version or webpage. 
Here is what you would do with that table after it's a SAS data set*/

/*Create a table of the list of countries and abbreviations from online file. I am creating this manually
because I didn't want to lookup an entire list*/
data ctryLookup;
	infile datalines dsd;
	input CtryAbb:$3. CountryName:$30.;
	datalines;
US, United States
GR, Greece
CA, Canada
;
run;


/*Once you find a table list, you need to create the following columns*/
/* 
   -start  (value to look for)
   -label  (how to label that value found)
   -fmtname (name of the format to create)
*/
data formatInputTBL;
	set ctryLookup(rename=(CtryAbb=Start
						   CountryName=Label));
	fmtName='$ctryFormat';
run;

/*Create a format using the above table as input and the CNTLIN option to create a format from a table*/
proc format cntlin=work.formatInputTBL;
run;

/*View the new format you created*/
proc format lib=work;
	select $ctryformat;
run;

/*Use that format to create a new column (or overwrite an existing column)*/
data Newtable;
	set ctry;
	Fullname = put(Country, $ctryformat.);
run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;- Peter&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 19:22:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623662#M19972</guid>
      <dc:creator>Panagiotis</dc:creator>
      <dc:date>2020-02-10T19:22:27Z</dc:date>
    </item>
    <item>
      <title>Re: Code that finds and replaces character value in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623671#M19974</link>
      <description>You want a format, you'll need to build a custom format though. &lt;BR /&gt;I think the SASHELP.ZIPCODE file will have the data you need. &lt;BR /&gt;&lt;BR /&gt;This thread may be helpful. &lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/Function-for-FIPS-codes-by-County/td-p/470125" target="_blank"&gt;https://communities.sas.com/t5/SAS-Procedures/Function-for-FIPS-codes-by-County/td-p/470125&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=n01f5qrjoh9h4hn1olbdpb5pr2td.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;If you have codes (FIPS) there's a bunch of functions that will do the mapping for you as well.&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 10 Feb 2020 20:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623671#M19974</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-10T20:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: Code that finds and replaces character value in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623694#M19976</link>
      <description>&lt;P&gt;I forgot about those SASHELP tables.&amp;nbsp; Great idea.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Peter&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 20:47:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623694#M19976</guid>
      <dc:creator>Panagiotis</dc:creator>
      <dc:date>2020-02-10T20:47:48Z</dc:date>
    </item>
    <item>
      <title>Re: Code that finds and replaces character value in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623711#M19980</link>
      <description>&lt;P&gt;The "If-Then" statement worked for me.&amp;nbsp; I have an excel sheet with a column for the list of abbreviations and another column with the corresponding full name.&amp;nbsp; Is there syntax I can use to incorporate that file so that I don't have to enter in 100 county names?&amp;nbsp; &amp;nbsp;Alternatively, could I use:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname rabdata xlsx "/folders/myfolders/sasuser.v94/2019RabData_Raw.XLS.xlsx";&lt;/P&gt;&lt;P&gt;data newtable;&lt;BR /&gt;set rabdata.rab19;&lt;BR /&gt;If Animal_Address_County="FRA" then Animal_Address_County="FRANKLIN";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data newtable;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;infile countyname.xlsx;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;input Animal_Address_County:$30.;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;FRAN, Franklin&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;A, Ash&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Lay, Layton;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 21:58:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623711#M19980</guid>
      <dc:creator>AJS1</dc:creator>
      <dc:date>2020-02-10T21:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Code that finds and replaces character value in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623745#M19986</link>
      <description>If you have the data in a data set you should import that data and then use either a JOIN/MERGE or FORMAT using a CNTLIN data set to create the format. You cannot easily change that to an IF/THEN structure.</description>
      <pubDate>Tue, 11 Feb 2020 04:36:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623745#M19986</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-02-11T04:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Code that finds and replaces character value in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623828#M20002</link>
      <description>&lt;P&gt;Since you have the data you can follow the PROC FORMAT CNTLIN from the solution. That'll create a format from a table. That's definitely the easiest way. No way I would write 100 IF-THENS.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also learn about SQL JOINS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Peter&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 13:16:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/623828#M20002</guid>
      <dc:creator>Panagiotis</dc:creator>
      <dc:date>2020-02-11T13:16:39Z</dc:date>
    </item>
    <item>
      <title>Re: Code that finds and replaces character value in a column</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/624346#M20087</link>
      <description>&lt;P&gt;I used the MERGE function but am unclear on how to write code to include the other columns in the dataset.&amp;nbsp; Do I need to include a KEEP statement somewhere?&amp;nbsp; How would I write a FORMAT/CNTLIN function to achieve the same results (I looked it up in SAS help but still find it confusing).&lt;/P&gt;&lt;PRE&gt;&lt;BR /&gt;&lt;BR /&gt;libname rabdata xlsx "/folders/myfolders/sasuser.v94/2019RabData_Raw.XLS.xlsx";&lt;BR /&gt;libname lits2 xlsx "/folders/myfolders/sasuser.v94/LITSCodes.xlsx";&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;proc sort data=lits2.sheet1;&lt;BR /&gt;    by An_Address_County;&lt;BR /&gt;run;&lt;BR /&gt;               &lt;BR /&gt;data rabdata.rab19;&lt;BR /&gt;	&lt;STRONG&gt;merge&lt;/STRONG&gt; lits2.sheet1;&lt;BR /&gt;	by An_Address_County;&lt;BR /&gt;	run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Feb 2020 20:56:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Code-that-finds-and-replaces-character-value-in-a-column/m-p/624346#M20087</guid>
      <dc:creator>AJS1</dc:creator>
      <dc:date>2020-02-12T20:56:06Z</dc:date>
    </item>
  </channel>
</rss>

