<?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: How to create one ID with a specific form from three messy ID columns in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558060#M155693</link>
    <description>&lt;P&gt;I have added some validity code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
       array idx $ id1-id3;  /* original data */

     /* assuming ID is the last of valid IDs */
      do i=1 to 3;
           idx(i) = upcase(idx(i));    /* ensure capital K */
           if  substr(idx(i),1,1) = 'K' and
               length(compress(idx(i),'K',kd) = 8  
            then id = idx(i);
     end;
run;     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as space is non valid ID then the last valid is choosed.&lt;/P&gt;</description>
    <pubDate>Sat, 11 May 2019 16:37:33 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2019-05-11T16:37:33Z</dc:date>
    <item>
      <title>How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558041#M155678</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a problem that cannot wrap my head around it... :&lt;/P&gt;
&lt;P&gt;I have this table:&lt;/P&gt;
&lt;TABLE width="256"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD colspan="3" width="192"&gt;HAVE&lt;/TD&gt;
&lt;TD width="64"&gt;WANT&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ID1&lt;/TD&gt;
&lt;TD&gt;ID2&lt;/TD&gt;
&lt;TD&gt;ID3&lt;/TD&gt;
&lt;TD&gt;ID&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;K02563087&lt;/TD&gt;
&lt;TD&gt;K02563087&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;0.035501&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;.0V0339435&lt;/TD&gt;
&lt;TD colspan="2"&gt;K03394375&lt;/TD&gt;
&lt;TD&gt;K03394375&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;KO3499516&lt;/TD&gt;
&lt;TD colspan="2"&gt;K03499516&lt;/TD&gt;
&lt;TD&gt;K03499516&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;K03508960&lt;/TD&gt;
&lt;TD&gt;K03339796&lt;/TD&gt;
&lt;TD&gt;K03339796&lt;/TD&gt;
&lt;TD&gt;K03339796&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;000030164219NCZUTL02&lt;/TD&gt;
&lt;TD colspan="2"&gt;K03415332&lt;/TD&gt;
&lt;TD&gt;K03415332&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;1E+09&lt;/TD&gt;
&lt;TD colspan="2"&gt;K02748355&lt;/TD&gt;
&lt;TD&gt;K02748355&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;EWOLFENWAFEN&lt;/TD&gt;
&lt;TD colspan="2"&gt;K03584884&lt;/TD&gt;
&lt;TD&gt;K03584884&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="2"&gt;EBILHOITE&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;ERICHARSON115&lt;/TD&gt;
&lt;TD colspan="2"&gt;K03656588&lt;/TD&gt;
&lt;TD&gt;K03656588&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;K03516138&lt;/TD&gt;
&lt;TD colspan="2"&gt;K01972934&lt;/TD&gt;
&lt;TD&gt;K01972934&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="2"&gt;K03516140&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;K03516140&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The first three columns are what I have and the fourth column is the ideal scenario.&lt;/P&gt;
&lt;P&gt;How would you approach this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Takis&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S. The correct format of ID is letter K and then 8 numbers&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 14:10:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558041#M155678</guid>
      <dc:creator>triunk</dc:creator>
      <dc:date>2019-05-11T14:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558047#M155682</link>
      <description>&lt;P&gt;Try next logic/code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
       array idx $ id1-id3;  /* original data */

     /* assuming ID is the last of valid IDs */
      do i=1 to 3;
           if  substr(idx(i),1,1) = 'K' then id = idx(i);
     end;
run;     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Check:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; - can an IDx &lt;STRONG&gt;start with 'K'&lt;/STRONG&gt; but have more alphabetic characters ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- can an IDx have less then 8 digits after the 'K' ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- Is it always capital 'K' ( never 'k') ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- Is there any case you will prefer the first IDx instead the last valid ?&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 15:38:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558047#M155682</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-05-11T15:38:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558048#M155683</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input (id1-id3)(:$20.);
infile datalines dsd missover dlm=',';
datalines;
,,K02563087
0.035501,,     
.0V0339435,K03394375, 
KO3499516,K03499516, 
K03508960,K03339796,K03339796
000030164219NCZUTL02,K03415332,
1E+09,K02748355, 
EWOLFENWAFEN,K03584884, 
EBILHOITE,,
ERICHARSON115,K03656588, 
K03516138,K01972934, 
K03516140,,
;

data want(drop=i j);
   set have;
   array id{3} $ id1-id3;
   do i=1 to dim(id);
      if char(id[i], 1) ne 'K' then id[i]=" ";
   end;
   do j=dim(id) to 1 by -1;
      if not missing(id[j]) then do;
         newvar=id[j];
         leave;
      end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 11 May 2019 15:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558048#M155683</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-05-11T15:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558049#M155684</link>
      <description>&lt;PRE&gt;WantID = &lt;SPAN&gt;COALESCEC&lt;/SPAN&gt;(ID3, ID2, ID1); &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then test for the validity of WantID (ie starting with K followed by 8 numbers)&lt;/P&gt;&lt;P&gt;Docs here for the function:&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p1g9btrql8d9x6n1iz6yowaqrq1v.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;Coalescec function&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 16:06:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558049#M155684</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2019-05-11T16:06:39Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558051#M155686</link>
      <description>&lt;P&gt;Hi Shmuel,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for these input and great questions:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; - can an IDx&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;start with 'K'&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;but have more alphabetic characters ?&lt;/P&gt;
&lt;P&gt;No it has to start with K and then have numbers if you see in ID1 one of the IDs has letter O instead of 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- can an IDx have less then 8 digits after the 'K' ?&lt;/P&gt;
&lt;P&gt;Nope&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- Is it always capital 'K' ( never 'k') ?&lt;/P&gt;
&lt;P&gt;yes it should be K although people may type it as k&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;- Is there any case you will prefer the first IDx instead the last valid ?&lt;/P&gt;
&lt;P&gt;yes if it is empty the ID3 I would prefere ID1 or ID2 that has this format&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope now it is more clear. Thank you again very much!&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 16:18:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558051#M155686</guid>
      <dc:creator>triunk</dc:creator>
      <dc:date>2019-05-11T16:18:09Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558052#M155687</link>
      <description>&lt;P&gt;a good way to check validity thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 16:18:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558052#M155687</guid>
      <dc:creator>triunk</dc:creator>
      <dc:date>2019-05-11T16:18:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558053#M155688</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78622"&gt;@ghosh&lt;/a&gt;&amp;nbsp;, please pay attention that according to documentation - COALESCE:&lt;/P&gt;
&lt;P&gt;"&lt;SPAN&gt;Returns the &lt;STRONG&gt;first&lt;/STRONG&gt; nonmissing value from a list of character arguments."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;and that it not what wanted according to given sample.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 16:22:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558053#M155688</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-05-11T16:22:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558054#M155689</link>
      <description>&lt;P&gt;The validity test is for you to code.&lt;BR /&gt;But COALESCEC will give you the ID value you need based on the non blank values of ID3 to ID1. Please note the order of the variables&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 16:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558054#M155689</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2019-05-11T16:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558055#M155690</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/88384"&gt;@Shmuel&lt;/a&gt;&lt;BR /&gt;It's actually the COALESCEC fn&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;From his sample, I understood he wants to pick the last of the IDn values if valid&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 16:29:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558055#M155690</guid>
      <dc:creator>ghosh</dc:creator>
      <dc:date>2019-05-11T16:29:53Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558060#M155693</link>
      <description>&lt;P&gt;I have added some validity code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
 set have;
       array idx $ id1-id3;  /* original data */

     /* assuming ID is the last of valid IDs */
      do i=1 to 3;
           idx(i) = upcase(idx(i));    /* ensure capital K */
           if  substr(idx(i),1,1) = 'K' and
               length(compress(idx(i),'K',kd) = 8  
            then id = idx(i);
     end;
run;     &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;as space is non valid ID then the last valid is choosed.&lt;/P&gt;</description>
      <pubDate>Sat, 11 May 2019 16:37:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/558060#M155693</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-05-11T16:37:33Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/560486#M156744</link>
      <description>&lt;P&gt;Hi Shmuel I was so excited and accepted your solution too soon.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I tried to run it it gives me this error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;12813 data want3;&lt;BR /&gt;12814 set have;&lt;BR /&gt;12815 array idx $ id1-id3; /* original data */&lt;BR /&gt;12816&lt;BR /&gt;12817 /* assuming ID is the last of valid IDs */&lt;BR /&gt;12818 do i=1 to 3;&lt;BR /&gt;12819 idx(i) = upcase(idx(i)); /* ensure capital K */&lt;BR /&gt;12820 if substr(idx(i),1,1) = 'K' and length(compress(idx(i),'K',kd) = 8&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;------&lt;BR /&gt;72&lt;BR /&gt;12821 then id = idx(i);&lt;BR /&gt;---- -&lt;BR /&gt;388 79&lt;BR /&gt;202&lt;BR /&gt;ERROR 72-185: The LENGTH function call has too many arguments.&lt;/P&gt;&lt;P&gt;ERROR 388-185: Expecting an arithmetic operator.&lt;/P&gt;&lt;P&gt;ERROR 79-322: Expecting a ).&lt;/P&gt;&lt;P&gt;ERROR 202-322: The option or parameter is not recognized and will be ignored.&lt;/P&gt;&lt;P&gt;12822 end;&lt;BR /&gt;12823 run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now as you see that I have one more comment that I did not make clear...&lt;/P&gt;&lt;P&gt;If I have in ID1: KO3524846 (letter O instead of number 0) but nothing on ID2 and ID3 how I can include in the code a correction of ID1 to K03524846 (all numbers)&lt;/P&gt;&lt;P&gt;If I have ID1:K03508960 (good format) and different ID2:K03339796 (good also format) how I can include in the code to take ID1 as correct?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I attach the table here again with those two revised examples:&lt;/P&gt;</description>
      <pubDate>Tue, 21 May 2019 13:26:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/560486#M156744</guid>
      <dc:creator>cgprog</dc:creator>
      <dc:date>2019-05-21T13:26:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to create one ID with a specific form from three messy ID columns</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/561728#M157308</link>
      <description>&lt;P&gt;Sorry for my late answer, as I was on vacation.&lt;/P&gt;
&lt;P&gt;Just in case you did not overcome yourself the error:&lt;/P&gt;
&lt;PRE&gt;12820 if substr(idx(i),1,1) = 'K' and length(compress(idx(i),'K',kd) = 8

 


------
72
12821 then id = idx(i);&lt;/PRE&gt;
&lt;P&gt;the code line should be:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if substr(idx(i),1,1) = 'K' and length(compress(idx(i)) , 'K' , kd ) = 8
then id = idx(i);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I have added a&amp;nbsp; ) at the right place.&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2019 11:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-create-one-ID-with-a-specific-form-from-three-messy-ID/m-p/561728#M157308</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-05-27T11:37:48Z</dc:date>
    </item>
  </channel>
</rss>

