<?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: Text to columns then changing the field order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337488#M272525</link>
    <description>&lt;P&gt;Thanks everyone for your help! I received a lot of great ideas so I ended up taking a piece from each and came up with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;Select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (substr(scan(ovr_new_value,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;),&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'"WRKP_MI'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) Minutes = scan(ovr_new_value, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'"WRKP_RE'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) TC = scan(ovr_new_value, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'"WRKP_TC'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) TYPE = scan(ovr_new_value, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Then repeated the above for the New2 and New3 columns. W&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;orks like a charm and does exactly what I want it to do.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Again, thanks!&amp;nbsp; You guys are awesome!!!&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 02 Mar 2017 18:32:13 GMT</pubDate>
    <dc:creator>kbos</dc:creator>
    <dc:date>2017-03-02T18:32:13Z</dc:date>
    <item>
      <title>Text to columns then changing the field order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337143#M272519</link>
      <description>&lt;P&gt;Hi all!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS EG so I am looking for some quick help. (Shout out to everyone for all the help I've been able to get from reading past posts!!)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a field that I have parsed out into 3 columns using the scan function:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Orig_Value&lt;/TD&gt;&lt;TD&gt;New1&lt;/TD&gt;&lt;TD&gt;New2&lt;/TD&gt;&lt;TD&gt;New3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"M=480","N=PTO","T=N"&lt;/TD&gt;&lt;TD&gt;"M=480"&lt;/TD&gt;&lt;TD&gt;"N=PTO"&lt;/TD&gt;&lt;TD&gt;"T=N"&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That works simple enough, but there are a few Orig_Value fields that have the same data, but in different order:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Orig_Value&lt;/TD&gt;&lt;TD&gt;New1&lt;/TD&gt;&lt;TD&gt;New2&lt;/TD&gt;&lt;TD&gt;New3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;"N=PTO","T=N","M=480"&lt;/TD&gt;&lt;TD&gt;"N=PTO"&lt;/TD&gt;&lt;TD&gt;"T=N"&lt;/TD&gt;&lt;TD&gt;"M=480"&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I get the values to line up in the same columns? So for example all the M=480s would be in New1, all the PTOs would be in New2...etc&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 20:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337143#M272519</guid>
      <dc:creator>kbos</dc:creator>
      <dc:date>2017-03-01T20:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Text to columns then changing the field order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337148#M272520</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;This probably will not help but..

If you do some cleanup you can use named input;

data want;
 input n=$ t=$ m=;
cards4;
N=PTO T=N M=480
N=ROG T=Y M=280
N=SAL T=N M=380
;;;;
run;quit;

Up to 40 obs WORK.WANT total obs=3

Obs     N     T     M

 1     PTO    N    480
 2     ROG    Y    280
 3     SAL    N    380

&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Mar 2017 21:06:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337148#M272520</guid>
      <dc:creator>rogerjdeangelis</dc:creator>
      <dc:date>2017-03-01T21:06:11Z</dc:date>
    </item>
    <item>
      <title>Re: Text to columns then changing the field order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337158#M272521</link>
      <description>&lt;P&gt;This comes close to what you are asking for.&amp;nbsp; It removes your original variable, and assigns different names to the final variables.&amp;nbsp; But it does split them while maintaining the order that you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;record_num = _n_;&lt;/P&gt;
&lt;P&gt;if orig_value &amp;gt; ' ';&lt;/P&gt;
&lt;P&gt;do i=1 to 5;&lt;/P&gt;
&lt;P&gt;value = scan(orig_value, i, ',');&lt;/P&gt;
&lt;P&gt;if value &amp;gt; ' ' then output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;proc transpose data=temp out=want (drop=_name_);&lt;/P&gt;
&lt;P&gt;var value;&lt;/P&gt;
&lt;P&gt;id value;&lt;/P&gt;
&lt;P&gt;by record_num;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;　&lt;/P&gt;
&lt;P&gt;This example assumes you have a maximum of five values on any one observation.&amp;nbsp; If there could be more, the DO loop would have to expand (such as 1 to 10 instead of 1 to 5).&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 22:00:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337158#M272521</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-01T22:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Text to columns then changing the field order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337160#M272522</link>
      <description>&lt;P&gt;Here is one way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  informat orig_value $50.;
  input orig_value &amp;amp;;
  array want(3)$ New1-New3;
  do i=1 to 3;
    if substr(scan(orig_value,i,','),1,3)='"M=' then New1=scan(orig_value,i,',');
    else if substr(scan(orig_value,i,','),1,3)='"N=' then New2=scan(orig_value,i,',');
    else if substr(scan(orig_value,i,','),1,3)='"T=' then New3=scan(orig_value,i,',');
  end;
  cards;
"M=480","N=PTO","T=N"
"N=PTO","T=N","M=480"
"N=PTO","T=N"
;
&lt;/PRE&gt;
&lt;P&gt;HTH,&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Mar 2017 22:06:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337160#M272522</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-01T22:06:20Z</dc:date>
    </item>
    <item>
      <title>Re: Text to columns then changing the field order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337216#M272523</link>
      <description>&lt;P&gt;call sortc()&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
infile cards dlm=',';
  input v1 $   v2 $ v3 $;
call sortc(of v1-v3);
  cards;
"M=480","N=PTO","T=N"
"N=PTO","T=N","M=480"
"N=PTO","T=N",.
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 02 Mar 2017 02:40:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337216#M272523</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-02T02:40:44Z</dc:date>
    </item>
    <item>
      <title>Re: Text to columns then changing the field order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337221#M272524</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;: sortc won't always produce the desired result. Here is one case where it will fail:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data want;
  infile cards dlm=',';
  input v1 $   v2 $ v3 $;
  call sortc(of v1-v3);
  cards;
"M=480","N=PTO","T=N"
"N=PTO","T=N","M=480"
"N=PTO","T=N",.
"M=PTO","T=N",.
;
run;
&lt;/PRE&gt;
&lt;P&gt;Art&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 03:21:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337221#M272524</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-02T03:21:59Z</dc:date>
    </item>
    <item>
      <title>Re: Text to columns then changing the field order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337488#M272525</link>
      <description>&lt;P&gt;Thanks everyone for your help! I received a lot of great ideas so I ended up taking a piece from each and came up with this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;Select&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (substr(scan(ovr_new_value,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;),&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;8&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;));&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'"WRKP_MI'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) Minutes = scan(ovr_new_value, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'"WRKP_RE'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) TC = scan(ovr_new_value, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;when&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'"WRKP_TC'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) TYPE = scan(ovr_new_value, &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;','&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Then repeated the above for the New2 and New3 columns. W&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;orks like a charm and does exactly what I want it to do.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;Again, thanks!&amp;nbsp; You guys are awesome!!!&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Mar 2017 18:32:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Text-to-columns-then-changing-the-field-order/m-p/337488#M272525</guid>
      <dc:creator>kbos</dc:creator>
      <dc:date>2017-03-02T18:32:13Z</dc:date>
    </item>
  </channel>
</rss>

