<?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: DO UNTIL and INDEX function not working the way I expect it to work in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981259#M379058</link>
    <description>&lt;P&gt;BTW your issue with INDEX() comes from defining short_code with a length of 5.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;in_prev=index(last_tmp_cd, short_code);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will therefore only work for the first instance, because then you have 2 characters and 3 blanks in the first 5 bytes of your variable.&lt;/P&gt;
&lt;P&gt;See Maxim 46!! Always define variables only for the needed length, and/or use TRIM() to get rid of the blanks at the end.&lt;/P&gt;</description>
    <pubDate>Tue, 23 Dec 2025 14:14:34 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2025-12-23T14:14:34Z</dc:date>
    <item>
      <title>DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981144#M379040</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've been scratching my head for the past few hours and thought an expert can help me. I have a list of names that belong to the same common entity.&amp;nbsp; I want to create unique 2 letter short codes using the names. I've written a program that should work (see result on row 2, where Harriet would create HA but because it was a duplicate of Ham, it removed A from the name to derive HR instead) but does not work for the subsequent record. Harry should have had A and R removed to derive HY&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD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/TD&gt;&lt;TD&gt;AL&lt;/TD&gt;&lt;TD&gt;HA,HR,HA,HE,HI,HO,HG,HO&lt;/TD&gt;&lt;TD&gt;HA,HR,HA,HE,HI,HO,HG&lt;/TD&gt;&lt;TD&gt;HOLLER&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;HU&lt;/TD&gt;&lt;TD&gt;Hummer&lt;/TD&gt;&lt;TD&gt;AL&lt;/TD&gt;&lt;TD&gt;HA,HR,HA,HE,HI,HO,HG,HO,HU&lt;/TD&gt;&lt;TD&gt;HA,HR,HA,HE,HI,HO,HG,HO&lt;/TD&gt;&lt;TD&gt;HUMMER&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is a full working example that produced the results above. Apologies in advance as I had to put a lot of comments to make sure my head is working correctly! I also added a few failsafes and bits and bobs to troubleshoot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;/*list of names*/&lt;BR /&gt;data tmp;&lt;BR /&gt;	length nam_1 $50;&lt;BR /&gt;	input nam_1;&lt;BR /&gt;	datalines;&lt;BR /&gt;Harry&lt;BR /&gt;Hummer&lt;BR /&gt;Harriet&lt;BR /&gt;Hog&lt;BR /&gt;Ham&lt;BR /&gt;Hello&lt;BR /&gt;Hogwarth&lt;BR /&gt;Hitachi&lt;BR /&gt;Holler&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;/*add a common field*/&lt;BR /&gt;data tmp;&lt;BR /&gt;	length short_code $5;&lt;BR /&gt;	set tmp;&lt;BR /&gt;	iso_a2="AL";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;/*objective: for the same common field (e.g. AL) short_code should be unique. short_code is derived from nam_1 (2 char)*/&lt;BR /&gt;&lt;BR /&gt;/*short_code is all empty*/&lt;BR /&gt;proc sort data=tmp;&lt;BR /&gt;	by iso_a2 descending short_code nam_1;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;data out;&lt;BR /&gt;	set tmp;&lt;BR /&gt;	by iso_a2 descending short_code nam_1;&lt;BR /&gt;	length tmp_cd last_tmp_cd $500;&lt;BR /&gt;	retain tmp_cd; /*i want to retain a list of short_codes that has been assigned for the same common field so i should not assign it again*/&lt;BR /&gt;	if first.iso_a2 then do; /*for every unique common fieldm, reset my short_code list*/&lt;BR /&gt;		tmp_cd=short_code;&lt;BR /&gt;	end;	&lt;BR /&gt;	&lt;BR /&gt;	/*begin creating short_code*/&lt;BR /&gt;	last_tmp_cd=tmp_cd; /*assign short_code from previous row to a new field to debug*/&lt;BR /&gt;	nam_1_s=upcase(nam_1); /*assign name to temporary var to be manipulated if required*/&lt;BR /&gt;	if short_code="" then do; /*assign short_code*/&lt;BR /&gt;		in_prev=1; /*do at least once*/&lt;BR /&gt;		do_cnt=0; /*failsafe for infinite loop*/&lt;BR /&gt;		do until (in_prev=0 or do_cnt=6);&lt;BR /&gt;			do_cnt=do_cnt+1; /*failsafe for infinite loop*/&lt;BR /&gt;			&lt;BR /&gt;			if do_cnt=1 then short_code=upcase(substr(nam_1_s,1,2)); /*if first loop, then simple assignment. take first 2 char of nam_1_s as short code. this will introduce dups*/&lt;BR /&gt;			else do; /*if not first loop it means there was a duplicate. now attempt to remove the char from nam_1_s*/&lt;BR /&gt;				to_rm=substr(strip(reverse(short_code)),1,1); /*extract the 2nd char of short_code and use this to remove this char from nam_1_s*/&lt;BR /&gt;				nam_1_s=cats(substr(nam_1_s,1,1),compress(substr(nam_1_s,2), to_rm, 'i')); /*keep first char and attempt to remove the next char*/&lt;BR /&gt;				short_code=upcase(substr(nam_1_s,1,2)); &lt;BR /&gt;				put last_tmp_cd=;&lt;BR /&gt;				put short_code=;&lt;BR /&gt;				put nam_1_s=;&lt;BR /&gt;				&lt;BR /&gt;			end;&lt;BR /&gt;			/*as in you see in the logs, it works for the first duplicate short_code. but subsequent short_codes fail to get index value&amp;gt;0 even though th short_code value is in last_tmp_cd*/&lt;BR /&gt;			in_prev=index(last_tmp_cd, short_code);&lt;BR /&gt;&lt;BR /&gt;		end;&lt;BR /&gt;	end;&lt;BR /&gt;	&lt;BR /&gt;	tmp_cd=catx(",",tmp_cd,short_code); /*add assigned short_code to the list so next short_code will not use the same value*/&lt;BR /&gt;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 21 Dec 2025 07:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981144#M379040</guid>
      <dc:creator>dylanleong78</dc:creator>
      <dc:date>2025-12-21T07:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981145#M379041</link>
      <description>&lt;P&gt;What should happen if the same name appears multiple times?&lt;/P&gt;
&lt;P&gt;And what should happen if you run out of characters from the name while building the short code? Would you try to use any character from the alphabet?&lt;/P&gt;</description>
      <pubDate>Sun, 21 Dec 2025 13:39:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981145#M379041</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-12-21T13:39:47Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981150#M379042</link>
      <description>Hi Kurt, there shouldn't be any duplicate names for an entity. I have handled that in a separate step. I did think about the running out of characters but in theory there are only a handful (100+) of these spread across multiple entities left that needed the distinct short codes by entity.so they shouldn't run out of characters and if there are special cases like these, i will assign some default char like X. The problem I am facing is that in my head, my code should work</description>
      <pubDate>Sun, 21 Dec 2025 18:29:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981150#M379042</guid>
      <dc:creator>dylanleong78</dc:creator>
      <dc:date>2025-12-21T18:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981153#M379043</link>
      <description>&lt;P&gt;Most likely the issue is using INDEX() when you actually want INDEXW() or better still the FINDW() function because of the TRIME modifier it allows.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input nam_1 :$50. iso_a2 :$2. ;
cards;
Ham AL
Harriet AL
Harry AL
Hello AL
Hitachi AL
Hog AL
Hogwarth  AL
Holler  AL
Hummer  AL
; 

data want;
  set have;
  by iso_a2 ;
  length short_code $2 list $100 ;
  retain list;
  if first.iso_a2 then call missing(list);
  do index=2 to length(nam_1) until(not found);
    short_code=upcase(cats(char(nam_1,1),char(nam_1,index)));
    found = findw(list,short_code,',','it');
  end;
  list=catx(',',list,short_code);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2025-12-21 at 3.15.18 PM.png" style="width: 728px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112382i1524C86E0425B4B9/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2025-12-21 at 3.15.18 PM.png" alt="Screenshot 2025-12-21 at 3.15.18 PM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;What is it you want to do when you get to something where there is no unique second letter to use?&lt;/P&gt;</description>
      <pubDate>Sun, 21 Dec 2025 21:27:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981153#M379043</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-12-21T21:27:52Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981258#M379057</link>
      <description>&lt;P&gt;Instead of using a RETAINed character variable, which is limited in length (with longer codes and source "names" you could crack the 32K limit), I recommend to use a hash object, which makes finding an existing entry that much easier (and faster, as a binary tree search will always outperform a sequential scan) and which is limited in size only by available memory.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
length nam_1 $50;
input nam_1;
iso_a2 = "AL";
datalines;
Harry
Hummer
Harriet
Hog
Ham
Hello
Hogwarth
Hitachi
Holler
;

proc sort data=have;
by iso_a2 nam_1;
run;

data want;
set have;
by iso_a2;
length short_code $2;

if _n_ = 1
then do;
  declare hash code ();
  code.definekey("short_code");
  code.definedata("short_code");
  code.definedone();
end;
if first.iso_a2 then code.clear();
nam_u = upcase(nam_1);
short_code = substr(nam_u,1,2);
if code.find() ne 0
then code.add();
else do;
  i1 = 2;
  i2 = 64;
  do until (code.find() ne 0 or i2 gt 90);
    if i1 lt length(nam_u)
    then do;
      i1 + 1;
      short_code = substr(nam_u,1,1) !! substr(nam_u,i1,1);
    end;
    else do;
      i2 + 1;
      short_code = substr(nam_u,1,1) !! byte(i2);
    end;
  end;
  if i2 gt 90
  then putlog "run out of characters";
  else code.add();
end;
drop nam_u i1 i2;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Dec 2025 14:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981258#M379057</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-12-23T14:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981259#M379058</link>
      <description>&lt;P&gt;BTW your issue with INDEX() comes from defining short_code with a length of 5.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;in_prev=index(last_tmp_cd, short_code);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;will therefore only work for the first instance, because then you have 2 characters and 3 blanks in the first 5 bytes of your variable.&lt;/P&gt;
&lt;P&gt;See Maxim 46!! Always define variables only for the needed length, and/or use TRIM() to get rid of the blanks at the end.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Dec 2025 14:14:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981259#M379058</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2025-12-23T14:14:34Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981261#M379059</link>
      <description>thanks a lot for this! sorry it took me awhile to respond. i wanted to make sure applying this logic in my full implementation works.</description>
      <pubDate>Tue, 23 Dec 2025 15:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981261#M379059</guid>
      <dc:creator>dylanleong78</dc:creator>
      <dc:date>2025-12-23T15:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981263#M379060</link>
      <description>thanks. i tried putting short_code=strip(upcase(substr(nam_1_s,1,2)));&lt;BR /&gt;&lt;BR /&gt;but it did not work. then i placed the strip in in_prev=index(last_tmp_cd, short_code); and that worked!</description>
      <pubDate>Tue, 23 Dec 2025 15:19:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981263#M379060</guid>
      <dc:creator>dylanleong78</dc:creator>
      <dc:date>2025-12-23T15:19:51Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981265#M379061</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/362347"&gt;@dylanleong78&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;thanks. i tried putting short_code=strip(upcase(substr(nam_1_s,1,2)));&lt;BR /&gt;&lt;BR /&gt;but it did not work. then i placed the strip in in_prev=index(last_tmp_cd, short_code); and that worked!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The reason that putting the STRIP() function call in an ASSIGNMENT statement did not help is because the trailing spaces were added back when the value was stored into the fixed length character variable.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Dec 2025 16:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981265#M379061</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-12-23T16:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: DO UNTIL and INDEX function not working the way I expect it to work</title>
      <link>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981266#M379062</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/362347"&gt;@dylanleong78&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;thanks a lot for this! sorry it took me awhile to respond. i wanted to make sure applying this logic in my full implementation works.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note that there is a lot of simplification in the code I posted.&amp;nbsp;&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When using UNTIL() there is no need for an extra test to insure the DO loop executes at least once.&lt;/LI&gt;
&lt;LI&gt;You can add an UNTIL() (or a WHILE()) clause to a normal iterative DO loop. So there is no need to increment your loop counter on your own.&lt;/LI&gt;
&lt;LI&gt;You can use CAT... series of functions to simplify building strings from other strings and even numbers.&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;And a comment on comments.&amp;nbsp; If you place the comments that explain the code BEFORE the code instead of after it then it is much easier&amp;nbsp;to understand the code.&amp;nbsp; Plus it will keep you from making lines that are too long for humans to read.&amp;nbsp; With long lines in addition to scanning down the page you have to keep sweeping the field of focus left and right.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Dec 2025 16:43:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/DO-UNTIL-and-INDEX-function-not-working-the-way-I-expect-it-to/m-p/981266#M379062</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-12-23T16:43:44Z</dc:date>
    </item>
  </channel>
</rss>

