<?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: Substituting 3rd element in the list in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319285#M70074</link>
    <description>Thank you KurtBremser. There are many SVD that we don't need to change that is why we need to go by the given rows. But your code logic is really helpful.</description>
    <pubDate>Thu, 15 Dec 2016 15:07:04 GMT</pubDate>
    <dc:creator>athapa1183</dc:creator>
    <dc:date>2016-12-15T15:07:04Z</dc:date>
    <item>
      <title>Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319251#M70056</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;&lt;P&gt;i have a looping and substitution problem in sas&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The Data is&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input string :$150.;&lt;BR /&gt;datalines;&lt;BR /&gt;stevdend*kdioror*kdkdkd&lt;BR /&gt;SVD*H2459**HC:93000**1~&lt;BR /&gt;fakdlkfjajdf*kdkfkldlk*kdkdk&lt;BR /&gt;dkfjaokldjfkj*jkdkjfk*kdkkd&lt;BR /&gt;woososdlsld*ldlldkdka*lkswkd&lt;BR /&gt;SVD*H2459**HC:1090F:8P**0~&lt;BR /&gt;qwwkfjajdf*grekfkldlk*grgrrgkdk&lt;BR /&gt;xcvxcvaokldjfkj*aaadddrkjfk*qqksodjidf&lt;BR /&gt;woososdlsld*ldlldkdka*lkswkd&lt;BR /&gt;&lt;SPAN&gt;SVD*H2459**HC:1234K:4P**0~&lt;/SPAN&gt;&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the rows given to us &amp;nbsp;are 2,6,10 (there are 2060 such rows)&lt;/P&gt;&lt;P&gt;so whenever the row numbers are given, I want to populate the 3rd element with *0*&lt;/P&gt;&lt;P&gt;for example in row 2 in the data have, I want this&amp;nbsp;&lt;SPAN&gt;SVD*H2459*0*HC:93000**1~ (The 3rd element is populated with 0 now).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to this for all rows in the given list&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;MY CODE&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;%let list = 2,6,10;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if _N_ in (&amp;amp;list) then do ;&lt;BR /&gt;string= tranwrd(string,"**","*0*");&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;THE problem is it also changes the other blank in the same row to 0, which i don't want.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I also tried the Substr(string,11,1) = '0'; but it didn't help&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I also tried to use the scan function but it doesn't recognizes the blank (**) between stars.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Could Someone please help.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 13:56:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319251#M70056</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-12-15T13:56:01Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319262#M70061</link>
      <description>&lt;P&gt;Use SCAN to extract the components and then CATX() to recombine.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 14:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319262#M70061</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-15T14:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319264#M70062</link>
      <description>&lt;P&gt;You're most of the way there.&amp;nbsp; Your program has the right structure to it, and it's only a question of what&lt;/P&gt;
&lt;P&gt;goes inside the DO group.&amp;nbsp; Here's one possibility:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;found = index(string, '**');&lt;/P&gt;
&lt;P&gt;string = substr(string, 1, found) || '0' || substr(string, found+1);&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 14:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319264#M70062</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-15T14:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319265#M70063</link>
      <description>&lt;P&gt;First of all, I find it extremely sloppy to run logic per row number. One slight change in the dataset, and you end up with garbage.&lt;/P&gt;
&lt;P&gt;I'd rather have the logic controlled by the fact that the first "word" in the string is 'SVD'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
length newstring $150;
if scan(string,1,'*') = 'SVD'
then do;
  do i = 1 to countw(string,'*');
    if i = 3
    then newstring = catx('*',trim(newstring),'0');
    else newstring = catx('*',trim(newstring),scan(string,i,'*'));
  end;
  string = newstring;
end;
drop i newstring;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Dec 2016 14:28:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319265#M70063</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-15T14:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319270#M70065</link>
      <description>&lt;P&gt;Since the "*" seems to be a separator between the different elements of each row, why don't you use it&lt;/P&gt;
&lt;P&gt;to read your data in separate columns ? It makes further processing much simpler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile datalines dlm="*" missover dsd;
format var1-var6  $20.;
input var1-var6;

if var3=" " then var3="0";

datalines;
stevdend*kdioror*kdkdkd
SVD*H2459**HC:93000**1~
fakdlkfjajdf*kdkfkldlk*kdkdk
dkfjaokldjfkj*jkdkjfk*kdkkd
woososdlsld*ldlldkdka*lkswkd
SVD*H2459**HC:1090F:8P**0~
qwwkfjajdf*grekfkldlk*grgrrgkdk
xcvxcvaokldjfkj*aaadddrkjfk*qqksodjidf
woososdlsld*ldlldkdka*lkswkd
SVD*H2459**HC:1234K:4P**0~
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 15 Dec 2016 14:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319270#M70065</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-12-15T14:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319273#M70067</link>
      <description>&lt;P&gt;It is handy with regular expression.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  string="SVD*H2459**HC:1090F:8P**0~";
  insert=prxchange('s/\*\*/*0*/',1,string);
  put _all_;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 14:55:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319273#M70067</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2016-12-15T14:55:12Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319276#M70068</link>
      <description>Hi Reeza, As i mentioned the scan does not recognize the ** as a blank and is skipping to the next element with no blanks.</description>
      <pubDate>Thu, 15 Dec 2016 15:02:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319276#M70068</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-12-15T15:02:19Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319277#M70069</link>
      <description>Thank You Astounding..</description>
      <pubDate>Thu, 15 Dec 2016 15:02:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319277#M70069</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-12-15T15:02:45Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319282#M70071</link>
      <description>Thank you it seems to work but I need to concatanate all 6 columns at end.&lt;BR /&gt;it is really insightful.</description>
      <pubDate>Thu, 15 Dec 2016 15:04:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319282#M70071</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-12-15T15:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319283#M70072</link>
      <description>Thank you So much. But the expression differ.</description>
      <pubDate>Thu, 15 Dec 2016 15:05:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319283#M70072</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-12-15T15:05:14Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319284#M70073</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115177"&gt;@athapa1183&lt;/a&gt; wrote:&lt;BR /&gt;Hi Reeza, As i mentioned the scan does not recognize the ** as a blank and is skipping to the next element with no blanks.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Note the dsd option in &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s code. That's what causes the input statement to recognize two separators as a missing value.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 15:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319284#M70073</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-15T15:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319285#M70074</link>
      <description>Thank you KurtBremser. There are many SVD that we don't need to change that is why we need to go by the given rows. But your code logic is really helpful.</description>
      <pubDate>Thu, 15 Dec 2016 15:07:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319285#M70074</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-12-15T15:07:04Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319286#M70075</link>
      <description>&lt;P&gt;Ah yes, and make use of the "Quote" button so it becomes obvious which post you are answering to.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 15:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319286#M70075</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-15T15:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319287#M70076</link>
      <description>Sure. Thanks.</description>
      <pubDate>Thu, 15 Dec 2016 15:09:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319287#M70076</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-12-15T15:09:17Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319288#M70077</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115177"&gt;@athapa1183&lt;/a&gt; wrote:&lt;BR /&gt;Thank you KurtBremser. There are many SVD that we don't need to change that is why we need to go by the given rows. But your code logic is really helpful.&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;There has to be some logic which lines need to be changed. Implement that logic right here in that data step, or you will end up footing yourself in the shoot.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 15:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319288#M70077</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-12-15T15:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319292#M70080</link>
      <description>&lt;P&gt;You can concatenate the columns with catx but it won't take missing values into account (ie, you&lt;/P&gt;
&lt;P&gt;won't have two consecutive asteriks when a variable is missing).&lt;/P&gt;
&lt;P&gt;Otherwise, you can use cat and strip but you have to list each variable. Both cases are illustrated below :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mlogic mprint;

data want;
infile datalines dlm="*" missover dsd;
format var1-var6  $20. var7 $150.;
input var1-var6;

if var3=" " then var3="0";

/* Other operations ... */

var7=catx("*",of var1-var6);
var8=cat(strip(var1),"*",strip(var2),"*", strip(var3),"*", strip(var4),"*",strip(var5),"*",strip(var6));


datalines;
stevdend*kdioror*kdkdkd
SVD*H2459**HC:93000**1~
fakdlkfjajdf*kdkfkldlk*kdkdk
dkfjaokldjfkj*jkdkjfk*kdkkd
woososdlsld*ldlldkdka*lkswkd
SVD*H2459**HC:1090F:8P**0~
qwwkfjajdf*grekfkldlk*grgrrgkdk
xcvxcvaokldjfkj*aaadddrkjfk*qqksodjidf
woososdlsld*ldlldkdka*lkswkd
SVD*H2459**HC:1234K:4P**0~
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;With the second method, you have to remove the trailing "***" on the non SVD rows if you want to keep the original structure of rows.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Dec 2016 15:28:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319292#M70080</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2016-12-15T15:28:00Z</dc:date>
    </item>
    <item>
      <title>Re: Substituting 3rd element in the list</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319382#M70134</link>
      <description>it is clear with the cat &amp;amp; strip option.&lt;BR /&gt;Thank you</description>
      <pubDate>Thu, 15 Dec 2016 20:42:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Substituting-3rd-element-in-the-list/m-p/319382#M70134</guid>
      <dc:creator>athapa1183</dc:creator>
      <dc:date>2016-12-15T20:42:36Z</dc:date>
    </item>
  </channel>
</rss>

