<?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 Transpose data whith array and conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data-whith-array-and-conditions/m-p/623721#M183668</link>
    <description>&lt;P&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My objectif&amp;nbsp; in this work is to create a new table with only 3 columns. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;when the value of the observation contains v1 it will be in col1 is so on.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I made this program, it works correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I wonder if you have other solutions to offer me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you .&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards dlm=' ' ;
input (var1-var9) ($7.);

cards;
Obs1V1 Obs1V2 Obs1V3 Obs2V1 Obs2V2 Obs2V3 Obs3V1 Obs3V2 Obs3V3
Obs4V1 Obs4V2 Obs4V3 Obs5V1 Obs5V2 Obs5V3 Obs6V1 Obs6V2 Obs6V3
Obs7V1 Obs7V2 Obs7V3
; run;

data test1(drop=var1-var9);
set test;
array vec(*) var1-var9;
array col(3) $ col1-col3;
do i=1 to dim(vec);
 if find(vec(i),'v1','i') ge 1 then 
 col1=vec(i);
  if find(vec(i),'v2','i') ge 1 then 
 col2=vec(i);
 if find(vec(i),'v3','i') ge 1 then 
 col3=vec(i);
 if i in (3,6, 9) then 
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 10 Feb 2020 23:15:09 GMT</pubDate>
    <dc:creator>mansour_ib_sas</dc:creator>
    <dc:date>2020-02-10T23:15:09Z</dc:date>
    <item>
      <title>Transpose data whith array and conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data-whith-array-and-conditions/m-p/623721#M183668</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;My objectif&amp;nbsp; in this work is to create a new table with only 3 columns. &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;when the value of the observation contains v1 it will be in col1 is so on.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I made this program, it works correctly.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I wonder if you have other solutions to offer me.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you .&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards dlm=' ' ;
input (var1-var9) ($7.);

cards;
Obs1V1 Obs1V2 Obs1V3 Obs2V1 Obs2V2 Obs2V3 Obs3V1 Obs3V2 Obs3V3
Obs4V1 Obs4V2 Obs4V3 Obs5V1 Obs5V2 Obs5V3 Obs6V1 Obs6V2 Obs6V3
Obs7V1 Obs7V2 Obs7V3
; run;

data test1(drop=var1-var9);
set test;
array vec(*) var1-var9;
array col(3) $ col1-col3;
do i=1 to dim(vec);
 if find(vec(i),'v1','i') ge 1 then 
 col1=vec(i);
  if find(vec(i),'v2','i') ge 1 then 
 col2=vec(i);
 if find(vec(i),'v3','i') ge 1 then 
 col3=vec(i);
 if i in (3,6, 9) then 
output;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Feb 2020 23:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-data-whith-array-and-conditions/m-p/623721#M183668</guid>
      <dc:creator>mansour_ib_sas</dc:creator>
      <dc:date>2020-02-10T23:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose data whith array and conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data-whith-array-and-conditions/m-p/623724#M183670</link>
      <description>&lt;P&gt;Read it differently?&lt;/P&gt;
&lt;PRE&gt;data test;
infile cards dlm=' ' ;
input (col1-col3) ($) @@ ;

cards;
Obs1V1 Obs1V2 Obs1V3 Obs2V1 Obs2V2 Obs2V3 Obs3V1 Obs3V2 Obs3V3
Obs4V1 Obs4V2 Obs4V3 Obs5V1 Obs5V2 Obs5V3 Obs6V1 Obs6V2 Obs6V3
Obs7V1 Obs7V2 Obs7V3
; 
run;&lt;/PRE&gt;
&lt;P&gt;Perhaps you need to give a bit more realistic example of the data. If the V1, V2 And V3 actually appear in different order than 1&amp;nbsp; 2&amp;nbsp; 3 then show some values out of order. Your example data does not actually require the Find.&lt;/P&gt;
&lt;PRE&gt;data test1(drop=var1-var9);
set test;
array vec(*) var1-var9;
array col(3) $ col1-col3;
do i=1 to dim(vec);
 col(mod(i,3) +1)=vec(i);
 if i in (3,6, 9) and not missing(vec(i)) then output;
end;
run;&lt;/PRE&gt;
&lt;P&gt;Might still be done by reading and then sorting:&lt;/P&gt;
&lt;PRE&gt;data test;
infile cards dlm=' ' ;
input (col1-col3) ($) @@ ;
array c col1-col3;
call sortc(of c(*));

cards;
Obs1V2 Obs1V1 Obs1V3 Obs2V3 Obs2V2 Obs2V1 Obs3V1 Obs3V2 Obs3V3
Obs4V1 Obs4V2 Obs4V3 Obs5V1 Obs5V2 Obs5V3 Obs6V1 Obs6V2 Obs6V3
Obs7V1 Obs7V2 Obs7V3
; 
run;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Feb 2020 00:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-data-whith-array-and-conditions/m-p/623724#M183670</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-02-11T00:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Transpose data whith array and conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Transpose-data-whith-array-and-conditions/m-p/623736#M183676</link>
      <description>&lt;P&gt;If you are starting with raw data, I would go wilth &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;'s last suggestion.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is the equivalent if you already have data set TEST:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
infile cards dlm=' ' ;
input (var1-var9) ($7.);
cards;
Obs1V1 Obs1V2 Obs1V3 Obs2V1 Obs2V2 Obs2V3 Obs3V1 Obs3V2 Obs3V3
Obs4V1 Obs4V2 Obs4V3 Obs5V1 Obs5V2 Obs5V3 Obs6V1 Obs6V2 Obs6V3
Obs7V1 Obs7V2 Obs7V3
;

data test1 (where=(cats(var1,var2,var3)^=' '));
  set test (keep=var1-var3);
  output;
  set test (keep=var4-var6 rename=(var4=var1 var5=var2 var6=var3));
  output;
  set test (keep=var7-var9 rename=(var7=var1 var8=var2 var9=var3));
  output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Feb 2020 02:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Transpose-data-whith-array-and-conditions/m-p/623736#M183676</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-02-11T02:15:35Z</dc:date>
    </item>
  </channel>
</rss>

