<?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: Map codes between different lengths in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358134#M84130</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's difficult to guess what you are after from what you posted.You are not helping yourself here by putting so little effort into this post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe that's what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
infile cards pad;
input CATEGORY $3. CODE : $9.;
 cards;
aaa 202020201
aaa 20202
bbb 450011111
bbb 45001
bbb 450011111
cc 466667777
cc 46666
dd 333332221
dd 33333
ee 45616
ee 232324343
ee 456166661
run;
     
proc sql;
  create table CODEMAP  as
    select unique SHORTCODE as START
                , LONGCODE  as LABEL
                , 'map'     as FMTNAME
                , 'c'       as TYPE
    from HAVE(rename=(CODE=SHORTCODE) where=(length(SHORTCODE)=5))
       , HAVE(rename=(CODE=LONGCODE ) where=(length(LONGCODE )=9))
    where  put(LONGCODE,$5.) = SHORTCODE;
quit; 

proc format cntlin=CODEMAP; 
run;

data WANT; 
  set HAVE; 
  CODE=put(CODE,$map.);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or maybe not.&lt;/P&gt;</description>
    <pubDate>Fri, 12 May 2017 05:47:29 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2017-05-12T05:47:29Z</dc:date>
    <item>
      <title>Map codes between different lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358106#M84120</link>
      <description>&lt;P&gt;Hi,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lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What i want is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="134"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;Category&lt;/TD&gt;
&lt;TD width="70"&gt;Code&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;aaa&lt;/TD&gt;
&lt;TD&gt;202020201&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;aaa&lt;/TD&gt;
&lt;TD&gt;202020201&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;bbb&lt;/TD&gt;
&lt;TD&gt;450011111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;bbb&lt;/TD&gt;
&lt;TD&gt;450011111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;bbb&lt;/TD&gt;
&lt;TD&gt;450011111&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;cc&lt;/TD&gt;
&lt;TD&gt;466667777&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;cc&lt;/TD&gt;
&lt;TD&gt;466667777&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;dd&lt;/TD&gt;
&lt;TD&gt;333332221&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;dd&lt;/TD&gt;
&lt;TD&gt;333332221&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ee&lt;/TD&gt;
&lt;TD&gt;456166661&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ee&lt;/TD&gt;
&lt;TD&gt;232324343&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ee&lt;/TD&gt;
&lt;TD&gt;456166661&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Ganesh K&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 05:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358106#M84120</guid>
      <dc:creator>Ganeshk</dc:creator>
      <dc:date>2017-05-12T05:10:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to do this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358110#M84121</link>
      <description>&lt;P&gt;&amp;nbsp;What's the logic? What's the question?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tip: If you took the time to initially add detail your question this would have been an answer rather than a request for further details.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 04:01:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358110#M84121</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-12T04:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to do this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358112#M84122</link>
      <description>&lt;P&gt;For a category i have to convert&amp;nbsp;5 digit Code(20202) to 9 digit code (202020201).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 04:13:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358112#M84122</guid>
      <dc:creator>Ganeshk</dc:creator>
      <dc:date>2017-05-12T04:13:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to do this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358113#M84123</link>
      <description>&lt;P&gt;Not to repeat myself, but what's the rule/logic?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 04:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358113#M84123</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-12T04:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to do this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358121#M84124</link>
      <description>&lt;P&gt;logic is that for each category should have same code, but in my data i have 5 length code &amp;amp; 9 lenght code. so i need to make them as 9 length code.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 04:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358121#M84124</guid>
      <dc:creator>Ganeshk</dc:creator>
      <dc:date>2017-05-12T04:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to do this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358122#M84125</link>
      <description>&lt;P&gt;If the first 5 digits are unique, then use substr() to only extract those and use that for grouping/summarizing. If the first 5 digits are not unique, your issue can't be reliably solved.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 04:56:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358122#M84125</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-05-12T04:56:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to do this?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358126#M84127</link>
      <description>&lt;P&gt;You really still didn't say how. If you can't explain it, it's unlikely you can code it.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What if only the first 3 digits match? Is that a match?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Given your sample data this will replicate your problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by category descending code;
run;

data want;
set have;
by category descending code;
retain new_code;
if length(code)=9 then new_code=code;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 May 2017 05:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358126#M84127</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-12T05:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Map codes between different lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358134#M84130</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's difficult to guess what you are after from what you posted.You are not helping yourself here by putting so little effort into this post.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe that's what you want:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE;
infile cards pad;
input CATEGORY $3. CODE : $9.;
 cards;
aaa 202020201
aaa 20202
bbb 450011111
bbb 45001
bbb 450011111
cc 466667777
cc 46666
dd 333332221
dd 33333
ee 45616
ee 232324343
ee 456166661
run;
     
proc sql;
  create table CODEMAP  as
    select unique SHORTCODE as START
                , LONGCODE  as LABEL
                , 'map'     as FMTNAME
                , 'c'       as TYPE
    from HAVE(rename=(CODE=SHORTCODE) where=(length(SHORTCODE)=5))
       , HAVE(rename=(CODE=LONGCODE ) where=(length(LONGCODE )=9))
    where  put(LONGCODE,$5.) = SHORTCODE;
quit; 

proc format cntlin=CODEMAP; 
run;

data WANT; 
  set HAVE; 
  CODE=put(CODE,$map.);
run;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or maybe not.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 05:47:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358134#M84130</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2017-05-12T05:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: Map codes between different lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358203#M84149</link>
      <description>&lt;P&gt;Expanding Reeza's&amp;nbsp; reply just a little bit&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;try this:&lt;/P&gt;
&lt;PRE style="position: fixed; left: -1000px;"&gt;data HAVE;&lt;BR /&gt;infile cards pad;&lt;BR /&gt;input CATEGORY $3. CODE : $9. ;&lt;BR /&gt;code5=substr(code,1,5);&lt;BR /&gt;n+1;&lt;BR /&gt; cards;&lt;BR /&gt;aaa 202020201&lt;BR /&gt;aaa 20202&lt;BR /&gt;bbb 450011111&lt;BR /&gt;bbb 45001&lt;BR /&gt;bbb 450011111&lt;BR /&gt;cc 466667777&lt;BR /&gt;cc 46666&lt;BR /&gt;dd 333332221&lt;BR /&gt;dd 33333&lt;BR /&gt;ee 45616&lt;BR /&gt;ee 232324343&lt;BR /&gt;ee 456166661&lt;BR /&gt;proc sort;  by category code5 descending code;  proc print;&lt;BR /&gt;&lt;BR /&gt;data;  set; by category code5;&lt;BR /&gt;if first.code5 then  newcode=code;  retain newcode;&lt;BR /&gt;drop code  code5;&lt;BR /&gt;proc sort;  by n;&lt;BR /&gt;proc print;&lt;BR /&gt;run;   &lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data HAVE;&lt;BR /&gt;infile cards pad;&lt;BR /&gt;input CATEGORY $3. CODE : $9. ;&lt;BR /&gt;code5=substr(code,1,5);&lt;BR /&gt;n+1;&lt;BR /&gt; cards;&lt;BR /&gt;aaa 202020201&lt;BR /&gt;aaa 20202&lt;BR /&gt;bbb 450011111&lt;BR /&gt;bbb 45001&lt;BR /&gt;bbb 450011111&lt;BR /&gt;cc 466667777&lt;BR /&gt;cc 46666&lt;BR /&gt;dd 333332221&lt;BR /&gt;dd 33333&lt;BR /&gt;ee 45616&lt;BR /&gt;ee 232324343&lt;BR /&gt;ee 456166661&lt;BR /&gt;proc sort; by category code5 descending code; proc print;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data; set; by category code5;&lt;BR /&gt;if first.code5 then newcode=code; retain newcode;&lt;BR /&gt;drop code code5;&lt;BR /&gt;proc sort; by n;&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 11:22:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358203#M84149</guid>
      <dc:creator>Jim_G</dc:creator>
      <dc:date>2017-05-12T11:22:13Z</dc:date>
    </item>
    <item>
      <title>Re: Map codes between different lengths</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358233#M84157</link>
      <description>&lt;P&gt;Is there any chance these values represent Zip codes??? If so there is no way without much more information to supply a vaid 9&amp;nbsp; character Zip.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It may help to provide an example of what is going to be done with this data later.&lt;/P&gt;</description>
      <pubDate>Fri, 12 May 2017 13:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Map-codes-between-different-lengths/m-p/358233#M84157</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-12T13:59:48Z</dc:date>
    </item>
  </channel>
</rss>

