<?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 recoding values depending on the location in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825604#M326098</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a string variable that has items' scores. Each score has two fields. For example,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"010002 M0102 Z" in this row there are 7 items' scores, the first item's score is "01" and the last one is " Z" (there is space before Z since it should have two fields). I want to recode Z's and M's as 0 or missing depending on their locations.&lt;/P&gt;
&lt;P&gt;1. If M or Z is at the end then they should be&amp;nbsp; missing. If they are followed by a score then they will be recoded as "00".&lt;/P&gt;
&lt;P&gt;2. No matter where Zs are located Zs should be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I searched for similar questions but not sure how to handle the location part.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jul 2022 07:14:11 GMT</pubDate>
    <dc:creator>dustychair</dc:creator>
    <dc:date>2022-07-27T07:14:11Z</dc:date>
    <item>
      <title>recoding values depending on the location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825604#M326098</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;I have a string variable that has items' scores. Each score has two fields. For example,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"010002 M0102 Z" in this row there are 7 items' scores, the first item's score is "01" and the last one is " Z" (there is space before Z since it should have two fields). I want to recode Z's and M's as 0 or missing depending on their locations.&lt;/P&gt;
&lt;P&gt;1. If M or Z is at the end then they should be&amp;nbsp; missing. If they are followed by a score then they will be recoded as "00".&lt;/P&gt;
&lt;P&gt;2. No matter where Zs are located Zs should be missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I searched for similar questions but not sure how to handle the location part.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 07:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825604#M326098</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-07-27T07:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: recoding values depending on the location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825606#M326099</link>
      <description>&lt;P&gt;First a general comment: any single variable that holds "7 scores" is likely a problem. Variables should hold a single value. Second, you need to show some examples of the result. There are several ways to interpret "should be missing".&lt;/P&gt;
&lt;P&gt;Consider a potential value of&lt;/P&gt;
&lt;P&gt;"010002 Z0102 Z".&lt;/P&gt;
&lt;P&gt;Does setting the &lt;STRONG&gt;first&lt;/STRONG&gt; Z to "missing" result in&lt;/P&gt;
&lt;P&gt;"010002&amp;nbsp; 0102 Z" (2 spaces between the 2 and 0)&amp;nbsp; "010002 0102 Z" (1 space between the 2 and 0) or "010002 .0102 Z" (the default . as "missing" value character?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to replace inside the variable you may have a problem. You say that some M should be replaced with "00". Or do you mean that " M", a leading space and M, should be replaced by "00"? That is two different things.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 08:15:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825606#M326099</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-27T08:15:38Z</dc:date>
    </item>
    <item>
      <title>Re: recoding values depending on the location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825722#M326137</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;,&lt;BR /&gt;Zs and Ms hold two fields. So it is like " Z" (there is 1 space before Z). I want to recode it as " "( there are two spaces. My plan is to separate them. Actually I already have done it. So, I want to code something like : if the last variable has Z or M then do " ". if any variable has Z then do " " else any other variables has M then do 00. Or I am not sure if it is a good idea to separate them. Since the last response order might be different for some students. It is easy in wording but hard in coding &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 16:35:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825722#M326137</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-07-27T16:35:03Z</dc:date>
    </item>
    <item>
      <title>Re: recoding values depending on the location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825734#M326141</link>
      <description>&lt;P&gt;Maybe easier with the long string value. See if this gives you something that works.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   str="010002 Z0102 Z";
   /*replace ALL Z with missing*/
   str=translate(str,' ','Z');
   str2='010002 M0102 M';
   If countc(str2,'M')&amp;gt;0 then do i= 1 to countc(str2,'M');
      pos=index(str2,'M');
      if pos &amp;lt; length(str2) then str2=tranwrd(str2," M","00");
      else str2=translate(str2,' ','M');
   end;
   drop pos i;
run;&lt;/PRE&gt;
&lt;P&gt;I handle the Z and M differently because you have different rules. The Translate function replaces characters that appear in the third parameter with the corresponding positional value in the second parameter. You can change many characters this way but also works for just one. The Tranwrd function replaces the value of the second parameter with the entire value of the third if present. The loop is a possibly unstated requirement to handle up to 7 M values. The Countc function returns how many characters are found.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If have taken your statement for Z as the 2. No matter where Zs are located Zs should be missing. Which does contradict the rule 1 as far as Z values go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 16:45:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825734#M326141</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-07-27T16:45:34Z</dc:date>
    </item>
    <item>
      <title>Re: recoding values depending on the location</title>
      <link>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825742#M326144</link>
      <description>&lt;P&gt;The code itself is working but I don't think it is working properly. For example,&lt;/P&gt;
&lt;P&gt;0101010000 M M M M M M M is recoded as&lt;/P&gt;
&lt;P&gt;010101000000000000000000&lt;/P&gt;
&lt;P&gt;So, it has converted all of the Ms to 00. However, the last M should be missing.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 16:59:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/recoding-values-depending-on-the-location/m-p/825742#M326144</guid>
      <dc:creator>dustychair</dc:creator>
      <dc:date>2022-07-27T16:59:53Z</dc:date>
    </item>
  </channel>
</rss>

