<?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: Unable to switch a value from one row to another row in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289765#M59863</link>
    <description>&lt;P&gt;Thanks RW9.&lt;/P&gt;&lt;P&gt;It works fine .&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Aninda&lt;/P&gt;</description>
    <pubDate>Fri, 05 Aug 2016 10:13:32 GMT</pubDate>
    <dc:creator>aninda_metal</dc:creator>
    <dc:date>2016-08-05T10:13:32Z</dc:date>
    <item>
      <title>Unable to switch a value from one row to another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289760#M59860</link>
      <description>&lt;P&gt;Hello All.&lt;/P&gt;&lt;P&gt;I have a dataset like below.&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;patient_id &amp;nbsp; &amp;nbsp;sd1 &amp;nbsp; sd2 &amp;nbsp; sd3 &amp;nbsp; sd4 &amp;nbsp; sd5 &amp;nbsp; sd6&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="3"&gt;A1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; 4 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="3"&gt;A2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3 &amp;nbsp; &amp;nbsp; &amp;nbsp; 7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp; 9&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;I want to create a new dataset like below.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;patient_id &amp;nbsp; &amp;nbsp;sd1 &amp;nbsp; sd2 &amp;nbsp; sd3 &amp;nbsp; sd4 &amp;nbsp; sd5 &amp;nbsp; sd6&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="3"&gt;A1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6&amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="3"&gt;A2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;7&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9&amp;nbsp; &amp;nbsp; &amp;nbsp; . &amp;nbsp; &amp;nbsp; &amp;nbsp;. &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; .&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;How can I do this?Any leads will be appreciated.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;Regards,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT size="3"&gt;Aninda&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2016 09:34:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289760#M59860</guid>
      <dc:creator>aninda_metal</dc:creator>
      <dc:date>2016-08-05T09:34:13Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to switch a value from one row to another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289763#M59861</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;data have;
  p_id="A1"; sd1=2;sd2=.; sd3=4; sd4=.; sd5=6.; sd6=.;
run;
data want (drop=i tmp);
  set have;
  array sd sd:;
  tmp=tranwrd(catx(",",of sd{*}),".,","");
  call missing(of sd{*});
  do i=1 to countw(tmp,",");
    sd{i}=input(scan(tmp,i,","),best.);
  end;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Aug 2016 10:14:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289763#M59861</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-05T10:14:25Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to switch a value from one row to another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289764#M59862</link>
      <description>&lt;P&gt;Brute force attack, from a longtime procedural programmer &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id $ sd1-sd6;
cards;
A1 2 . 4 . 6 .
A2 . 3 7 . . 9
;
run;

data want;
set have;
array sd {*} sd1-sd6;
i1 = 1;
i2 = 2;
do until (i2 &amp;gt; dim(sd));
  do while (sd{i1} ne . and i2 &amp;lt;= dim(sd));
    i1 + 1;
    i2 + 1;
  end;
  if i2 &amp;lt;= dim(sd) then x = sd{i2};
  do while (i2 &amp;lt;= dim(sd) and x = .);
    i2 + 1;
    if i2 &amp;lt;= dim(sd) then x = sd{i2};
  end;
  if i2 &amp;lt;= dim(sd)
  then do;
    sd{i1} = sd{i2};
    sd{i2} = .;
  end;
end;
drop i1 i2 x;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Aug 2016 10:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289764#M59862</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-05T10:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to switch a value from one row to another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289765#M59863</link>
      <description>&lt;P&gt;Thanks RW9.&lt;/P&gt;&lt;P&gt;It works fine .&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Aninda&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2016 10:13:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289765#M59863</guid>
      <dc:creator>aninda_metal</dc:creator>
      <dc:date>2016-08-05T10:13:32Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to switch a value from one row to another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289766#M59864</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I just made a tiny change to make it more flexible. &amp;nbsp;Rather than specifying sd{6} - six elements, put array sd sd:; which means create an array of all elements with prefix sd.&lt;/P&gt;</description>
      <pubDate>Fri, 05 Aug 2016 10:15:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289766#M59864</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-05T10:15:26Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to switch a value from one row to another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289771#M59868</link>
      <description>&lt;P&gt;Yet another way:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id $ sd1-sd6;
cards;
A1 2 . 4 . 6 .
A2 . 3 7 . . 9
;
run;

data want(drop = i j);
   set have;
   array k[*] sd1 - sd6;
   do i = 1 to dim(k);
      if missing(k[i]) then
      do j = i + 1 to dim(k);
         if not missing(k[j]) then do;
            k[i] = k[j];
            k[j] = .;
            leave;
          end;
      end;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 05 Aug 2016 11:24:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289771#M59868</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-08-05T11:24:26Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to switch a value from one row to another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289959#M59936</link>
      <description>&lt;PRE&gt;

data have;
input patient_id $ sd1-sd6;
cards;
A1 2 . 4 . 6 .
A2 . 3 7 . . 9
;
run;
data want;
 set have;
 array x{*} sd1-sd6;
 array y{*} new1-new6;
 n=0;
 do i=1 to dim(x);
  if not missing(x{i}) then do;
   n+1;
   y{n}=x{i};
  end;
 end;
 drop n i sd1-sd6;
 run;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 06 Aug 2016 07:34:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/289959#M59936</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-06T07:34:57Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to switch a value from one row to another row</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/290089#M59982</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/97768"&gt;@aninda_metal&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks RW9.&lt;/P&gt;
&lt;P&gt;It works fine .&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Aninda&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you can do &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt; a favor by marking his post as the accepted solution.&lt;/P&gt;</description>
      <pubDate>Mon, 08 Aug 2016 06:03:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unable-to-switch-a-value-from-one-row-to-another-row/m-p/290089#M59982</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-08T06:03:12Z</dc:date>
    </item>
  </channel>
</rss>

