<?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 Replacing variable with corresponding code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257875#M49564</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have students&amp;nbsp;record where I have to replace&amp;nbsp;them with proper country code(I have 280 country code), language code(20 language code) and citizenship_status(6 citizenship status). Is 'Format' an efficient way because I have such a long list for country?&lt;/P&gt;
&lt;P&gt;Can you please tell me what should be&amp;nbsp;the best way to proceed. Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp;Last_Name &amp;nbsp; &amp;nbsp;Country &amp;nbsp; &amp;nbsp; &amp;nbsp;Language &amp;nbsp; &amp;nbsp;Citizenship_status&lt;/P&gt;
&lt;P&gt;101 &amp;nbsp; Mike &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; USA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;English &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Citizen&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;102 &amp;nbsp; Solomon &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Canada &amp;nbsp; &amp;nbsp; &amp;nbsp; French &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Permanent Resident&amp;nbsp;&lt;/P&gt;
&lt;P&gt;103 &amp;nbsp; Husain &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Alzeria &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Arabic &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Refugee&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output table will look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp;Last_Name &amp;nbsp; &amp;nbsp;Country &amp;nbsp; &amp;nbsp; &amp;nbsp;Language &amp;nbsp; &amp;nbsp;Citizenship_status&lt;/P&gt;
&lt;P&gt;101 &amp;nbsp; Mike &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;1&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;102 &amp;nbsp; Solomon &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23 &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;103 &amp;nbsp; Husain &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8 &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;4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 20 Mar 2016 21:09:40 GMT</pubDate>
    <dc:creator>mlogan</dc:creator>
    <dc:date>2016-03-20T21:09:40Z</dc:date>
    <item>
      <title>Replacing variable with corresponding code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257875#M49564</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;I have students&amp;nbsp;record where I have to replace&amp;nbsp;them with proper country code(I have 280 country code), language code(20 language code) and citizenship_status(6 citizenship status). Is 'Format' an efficient way because I have such a long list for country?&lt;/P&gt;
&lt;P&gt;Can you please tell me what should be&amp;nbsp;the best way to proceed. Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp;Last_Name &amp;nbsp; &amp;nbsp;Country &amp;nbsp; &amp;nbsp; &amp;nbsp;Language &amp;nbsp; &amp;nbsp;Citizenship_status&lt;/P&gt;
&lt;P&gt;101 &amp;nbsp; Mike &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; USA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;English &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;Citizen&lt;/SPAN&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;
&lt;P&gt;102 &amp;nbsp; Solomon &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Canada &amp;nbsp; &amp;nbsp; &amp;nbsp; French &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Permanent Resident&amp;nbsp;&lt;/P&gt;
&lt;P&gt;103 &amp;nbsp; Husain &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Alzeria &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Arabic &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Refugee&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output table will look like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ID &amp;nbsp; &amp;nbsp; &amp;nbsp;Last_Name &amp;nbsp; &amp;nbsp;Country &amp;nbsp; &amp;nbsp; &amp;nbsp;Language &amp;nbsp; &amp;nbsp;Citizenship_status&lt;/P&gt;
&lt;P&gt;101 &amp;nbsp; Mike &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 234&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;1&lt;/SPAN&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;102 &amp;nbsp; Solomon &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;23 &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; 8&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp;&lt;/P&gt;
&lt;P&gt;103 &amp;nbsp; Husain &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8 &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;4&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 21:09:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257875#M49564</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-03-20T21:09:40Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing variable with corresponding code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257885#M49567</link>
      <description>&lt;P&gt;I vote for 'Format'.&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 22:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257885#M49567</guid>
      <dc:creator>Haikuo</dc:creator>
      <dc:date>2016-03-20T22:59:53Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing variable with corresponding code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257887#M49568</link>
      <description>&lt;P&gt;+1 for Format -&amp;gt; but making sure that you're using the CNTLIN option to create the formats from a table, rather than via typing in the codes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example 4 here shows how to create the code for proc format&lt;/P&gt;
&lt;P&gt;Example 8 shows how to use the CNTLIN data set for proc format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/sugi30/001-30.pdf" target="_blank"&gt;http://www2.sas.com/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 20 Mar 2016 23:46:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257887#M49568</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-20T23:46:16Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing variable with corresponding code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257921#M49572</link>
      <description>&lt;P&gt;Personally I avoid formats where at all possible. &amp;nbsp;My suggestion would be to create a lookup dataset:&lt;/P&gt;
&lt;P&gt;CODE_LIST &amp;nbsp; &amp;nbsp; &amp;nbsp; CODE &amp;nbsp; &amp;nbsp; &amp;nbsp; DECODE&lt;/P&gt;
&lt;P&gt;COUNTRY &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; USA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;
&lt;P&gt;COUNTRY &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CANADA &amp;nbsp; &amp;nbsp;8&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;LANGUAGE &amp;nbsp; &amp;nbsp; &amp;nbsp; ENGLISH &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With this you can use is to either merge the data on, or as a lookup in SQL:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  A.ID,&lt;BR /&gt;          A.LAST_NAME,&lt;BR /&gt;          (select DECODE from CODES where upcase(CODE_LIST)="COUNTRY" and CODE=A.CODE) as COUNTRY_CODE&lt;BR /&gt;...&lt;/PRE&gt;
&lt;P&gt;If you ever have to deal with outside technology, i.e. XML, databases etc. you will find the above a quick transition.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 09:25:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257921#M49572</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-21T09:25:04Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing variable with corresponding code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257931#M49573</link>
      <description>&lt;P&gt;This question is the SAS equivalent of "who's the best guitar player after Jimi Hendrix?" and "what is the best text editor?".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In this case the popular contendors for table lookup techniques are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Datastep merge, key lookup&lt;/LI&gt;
&lt;LI&gt;SQL&lt;/LI&gt;
&lt;LI&gt;Formats&lt;/LI&gt;
&lt;LI&gt;Hash table&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;It is a matter of taste, the impact on performance, maintainability and so on&amp;nbsp;in relationship to your specific use case. No exact generally applicable answer can be given. Quite a few SUGI/SGF papers exist on the topic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(PS: Obviously, David Gilmour is the best guitar player after Jimi Hendrix.)&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 10:26:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257931#M49573</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2016-03-21T10:26:01Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing variable with corresponding code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257979#M49603</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Personally I avoid formats where at all possible. &amp;nbsp;My suggestion would be to create a lookup dataset:&lt;/P&gt;
&lt;P&gt;CODE_LIST &amp;nbsp; &amp;nbsp; &amp;nbsp; CODE &amp;nbsp; &amp;nbsp; &amp;nbsp; DECODE&lt;/P&gt;
&lt;P&gt;COUNTRY &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; USA &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&lt;/P&gt;
&lt;P&gt;COUNTRY &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CANADA &amp;nbsp; &amp;nbsp;8&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;LANGUAGE &amp;nbsp; &amp;nbsp; &amp;nbsp; ENGLISH &amp;nbsp; 6&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With this you can use is to either merge the data on, or as a lookup in SQL:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  A.ID,&lt;BR /&gt;          A.LAST_NAME,&lt;BR /&gt;          (select DECODE from CODES where upcase(CODE_LIST)="COUNTRY" and CODE=A.CODE) as COUNTRY_CODE&lt;BR /&gt;...&lt;/PRE&gt;
&lt;P&gt;If you ever have to deal with outside technology, i.e. XML, databases etc. you will find the above a quick transition.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the data is somewhat volatile then a data set and merge or join as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;suggests or&amp;nbsp;hash&amp;nbsp;is probably best. If the data actually fixed then I vote for format. And if the the is read from a "nice" data source possibly even an INFORMAT to create the codes when read avoiding an extra step of replacing them later.&lt;/P&gt;</description>
      <pubDate>Mon, 21 Mar 2016 15:08:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/257979#M49603</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-21T15:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing variable with corresponding code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/258588#M49841</link>
      <description>Hi RW9, I can't see your whole code here. Would you please complete it for me. Thanks,</description>
      <pubDate>Wed, 23 Mar 2016 17:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/258588#M49841</guid>
      <dc:creator>mlogan</dc:creator>
      <dc:date>2016-03-23T17:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing variable with corresponding code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/258601#M49850</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can't see it because I didn't post any.&amp;nbsp; Its whats called a snippet.&amp;nbsp; The salient part of the topic was that you can keep your formats, codelist (whatever you call them) as data in datasets and "lookup" the value using either a subquery (which is this part in the snippet):&lt;/P&gt;
&lt;PRE&gt;(select DECODE from CODES where upcase(CODE_LIST)="COUNTRY" and CODE=A.CODE) as COUNTRY_CODE&lt;/PRE&gt;
&lt;P&gt;Or by merging the data on.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 18:57:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/258601#M49850</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-03-23T18:57:23Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing variable with corresponding code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/258636#M49864</link>
      <description>&lt;P&gt;We can't provide code because you haven't provided data.&lt;/P&gt;
&lt;P&gt;I'm assuming that you would have predefined coding systems for the countries and other variables.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or would at least need to generate them...it's a multistep process.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 23 Mar 2016 21:18:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-variable-with-corresponding-code/m-p/258636#M49864</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-23T21:18:59Z</dc:date>
    </item>
  </channel>
</rss>

