<?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 first letter or value  or last letter or value in given set of observations. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403798#M98139</link>
    <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;I am pretty new to SAS, looking forward for your advice.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;I want to replace first letter and last letter in given set of observations.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;Below are my questions.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q1: I have a variable called Road_No and i have 5000 observations in that.&lt;/P&gt;&lt;P&gt;I would like to replace first letter of the observations with H. How&amp;nbsp;do i do it. Road_No is character variable and length of the observations are 7.&lt;/P&gt;&lt;P&gt;Example: Road_No are A001010,BC&lt;SPAN&gt;01010,and so on, I want replace the first letter of A and B to H001010 ,HC01010&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q2:&amp;nbsp;Same way how do i replace last digit with M.&lt;/P&gt;&lt;P&gt;Q3: How do i replace third digit. &amp;nbsp;Example: HA01011 To HAB1011&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Bidd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Oct 2017 05:31:25 GMT</pubDate>
    <dc:creator>BIDD</dc:creator>
    <dc:date>2017-10-13T05:31:25Z</dc:date>
    <item>
      <title>Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403798#M98139</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;I am pretty new to SAS, looking forward for your advice.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;I want to replace first letter and last letter in given set of observations.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10.5pt; font-family: 'Helvetica',sans-serif; color: #333333;"&gt;Below are my questions.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q1: I have a variable called Road_No and i have 5000 observations in that.&lt;/P&gt;&lt;P&gt;I would like to replace first letter of the observations with H. How&amp;nbsp;do i do it. Road_No is character variable and length of the observations are 7.&lt;/P&gt;&lt;P&gt;Example: Road_No are A001010,BC&lt;SPAN&gt;01010,and so on, I want replace the first letter of A and B to H001010 ,HC01010&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Q2:&amp;nbsp;Same way how do i replace last digit with M.&lt;/P&gt;&lt;P&gt;Q3: How do i replace third digit. &amp;nbsp;Example: HA01011 To HAB1011&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Bidd&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 05:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403798#M98139</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2017-10-13T05:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403802#M98140</link>
      <description>&lt;P&gt;You can try this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;newval=Compress('H'||substr(&lt;SPAN&gt;Road_No&amp;nbsp;&lt;/SPAN&gt;,2,1)||'B'||substr(&lt;SPAN&gt;Road_No&amp;nbsp;&lt;/SPAN&gt;,4,4));&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 05:47:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403802#M98140</guid>
      <dc:creator>HabAM</dc:creator>
      <dc:date>2017-10-13T05:47:37Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403806#M98141</link>
      <description>Hi, Thanks for your help..it helped me for Question 3..appreciate your advise for Q1 and Q2</description>
      <pubDate>Fri, 13 Oct 2017 06:00:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403806#M98141</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2017-10-13T06:00:18Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403815#M98143</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Are you creating three different variables from one or you are only interested in replacing the first, third and last?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 07:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403815#M98143</guid>
      <dc:creator>HabAM</dc:creator>
      <dc:date>2017-10-13T07:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403819#M98144</link>
      <description>&lt;P&gt;&lt;SPAN&gt;if you are creating three separate variables, this should work..&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data want;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;set have;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;first=Compress('H'||substr(&lt;/SPAN&gt;&lt;SPAN&gt;Road_No&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;,2,6)&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;second=&lt;SPAN&gt;Compress(substr(&lt;/SPAN&gt;&lt;SPAN&gt;Road_No&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;,1,6)||'M'&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;third=&lt;SPAN&gt;Compress(substr(&lt;/SPAN&gt;&lt;SPAN&gt;Road_No&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;,1,2)||'B'||substr(&lt;/SPAN&gt;&lt;SPAN&gt;Road_No&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;,4,4));&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;good luck&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 07:05:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403819#M98144</guid>
      <dc:creator>HabAM</dc:creator>
      <dc:date>2017-10-13T07:05:55Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403824#M98146</link>
      <description>&lt;P&gt;Try this...&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVe;  
INPUT VALUE $7.;
CARDS;
A001010
B001010
C001010
D001010
;
run;

data WANT;
  set HAVE;

value=ifc(substr(value,1,1) in ('A','B'), 'H'||substr(value,2), value); *replace 1st char if 'A' or 'B';

value = substr(value,1,6)||'M'; *REPLACE LAST CHAR;
value = substr(value,1,2)||'B'||substr(4,4); *REPLACE THIRD CHAR;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 07:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403824#M98146</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-10-13T07:52:18Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403830#M98148</link>
      <description>&lt;P&gt;There is a trick here which is useful to learn.&amp;nbsp; The substr function can appear on the left of an equals sign.&amp;nbsp; What this does is for the given substr command put the text from the right in, so you can do:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have;
  substr(road_no,1,1)="H";
  substr(road_no,lengthn(road_no)-1,1)="M";
  substr(road_no,3,1)="B";
run;&lt;/PRE&gt;
&lt;P&gt;So what we do here is with the substr specify where the characters on the right should go in the string.&amp;nbsp; In the second one I take the lengthn of the string and drop back one char to get the last char position.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Oct 2017 08:16:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403830#M98148</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-10-13T08:16:10Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403834#M98149</link>
      <description>Hi, Yes I am creating 3 different new variables keeping the original as reference, so all new variables new replacement with first digit, third and last.</description>
      <pubDate>Fri, 13 Oct 2017 08:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403834#M98149</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2017-10-13T08:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403838#M98151</link>
      <description>HI, I left office some time back, will check it on Monday, thanks for ur help.</description>
      <pubDate>Fri, 13 Oct 2017 08:54:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403838#M98151</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2017-10-13T08:54:32Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403839#M98152</link>
      <description>HI, will keep note of it, thanks for your advise...will&lt;BR /&gt;check running this on Monday</description>
      <pubDate>Fri, 13 Oct 2017 08:56:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403839#M98152</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2017-10-13T08:56:20Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403841#M98153</link>
      <description>Hi, I left office some time back, will try running this on Monday. thanks for your help.</description>
      <pubDate>Fri, 13 Oct 2017 09:00:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403841#M98153</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2017-10-13T09:00:58Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403842#M98154</link>
      <description>Hi, Yes I am creating 3 different new variables keeping the original as reference, so all new variables new replacement with first digit, third and last.</description>
      <pubDate>Fri, 13 Oct 2017 09:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403842#M98154</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2017-10-13T09:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Replacing first letter or value  or last letter or value in given set of observations.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403843#M98155</link>
      <description>HI, will keep note of it, thanks for your advise...will&lt;BR /&gt;check running this on Monday</description>
      <pubDate>Fri, 13 Oct 2017 09:03:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Replacing-first-letter-or-value-or-last-letter-or-value-in-given/m-p/403843#M98155</guid>
      <dc:creator>BIDD</dc:creator>
      <dc:date>2017-10-13T09:03:58Z</dc:date>
    </item>
  </channel>
</rss>

