<?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: Changing variable format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316883#M69310</link>
    <description>&lt;P&gt;Is there a typo in your last two examples (the last e should be an f)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you make any assumptions about the length of the variables? Is it always two componenents? Do you have 3 in each of the first and 4 in the second or is it dynamic?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it may be better if you posted a slightly larger sample that better illustrates some of the issues with your data. Otherwise, I suspect someone will provide an answer, and you'll respond with a variation and it's an inefficient circle.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2016 23:29:58 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-12-05T23:29:58Z</dc:date>
    <item>
      <title>Changing variable format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316879#M69309</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;drs 
a-b-c &lt;BR /&gt;c-d-e-f &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have the following variable: drs. I want to create a new variable for each component of that variable. Here is the output I am looking at :&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;drs1 drs2 drs3 drs4
a  b c 
c d e f&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My next step after being able to work on the above data is to transform the modified format into the original one&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;drs1 drs2 drs3 drs4
a  b d
c d e e&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;output&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;drs
a-b-d
c-d-e-e&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Dec 2016 23:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316879#M69309</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-05T23:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316883#M69310</link>
      <description>&lt;P&gt;Is there a typo in your last two examples (the last e should be an f)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you make any assumptions about the length of the variables? Is it always two componenents? Do you have 3 in each of the first and 4 in the second or is it dynamic?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think it may be better if you posted a slightly larger sample that better illustrates some of the issues with your data. Otherwise, I suspect someone will provide an answer, and you'll respond with a variation and it's an inefficient circle.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 23:29:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316883#M69310</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-05T23:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316891#M69312</link>
      <description>&lt;P&gt;Reeza,&lt;/P&gt;&lt;P&gt;Thank you for the reply. I changed the f to an e to indicate I worked on the data so it is not similar to the first one. The variable length can be up to 13 components: a-b-c-d-e-a-b-c-d-e-a-b-c&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;drs 
a-b-c-d
a-b-e-e
a-d-e-a-c-e
a-b-c-d-e-f-g-e-a
a-a
a-b 
a-b-c-d-e-f &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I just want to be able to convert it to signle variables format for each of the componenet and be able to create the same variable again. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 23:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316891#M69312</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-05T23:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316892#M69313</link>
      <description>&lt;P&gt;This uses several functions that you should know how to use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SCAN - allows you to access each item in the list&lt;/P&gt;
&lt;P&gt;COUNTW - counts the # of components&lt;/P&gt;
&lt;P&gt;CATX - allows you to recombine the components, using a hyphen as a separator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;These are common functions that you should spend some time learning, they're very useful.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you know you have a max of 13 this is relatively straightforward:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input drs $26.;
cards;
a-b-c-d
a-b-e-e
a-d-e-a-c-e
a-b-c-d-e-f-g-e-a
a-a
a-b 
a-b-c-d-e-f
;
run;

data want;
set have;

array dr(13) $ dr1-dr13;
n_drs = countw(drs, "-");

do i=1 to n_drs;
dr(i)=scan(drs, i, "-");
end;

combined = catx("-", of dr(*));
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 05 Dec 2016 23:48:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316892#M69313</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-12-05T23:48:04Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316974#M69344</link>
      <description>&lt;P&gt;Your post is unclear to me. &amp;nbsp;If you want each block of characters separated by a space out to an obs then:&lt;/P&gt;
&lt;PRE&gt;data want;
  length res $200;
  do i=1 to countw(drx," ");
    res=scan(drs,i," ");
    output;
  end;
run;&lt;/PRE&gt;
&lt;P&gt;I don't see why all to splitting up, then putting back together.&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2016 10:24:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/316974#M69344</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-12-06T10:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: Changing variable format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/317022#M69354</link>
      <description>&lt;P&gt;Thank you Reeza&amp;nbsp;for the solution and suggestions!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 06 Dec 2016 14:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-variable-format/m-p/317022#M69354</guid>
      <dc:creator>lillymaginta</dc:creator>
      <dc:date>2016-12-06T14:17:10Z</dc:date>
    </item>
  </channel>
</rss>

