<?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: Create variables as per separators in string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-as-per-separators-in-string/m-p/383539#M91482</link>
    <description>&lt;P&gt;Hi, here's another idea. I made the maximum number of diseses five (D1-D5) and the maimum lenght of any disease twenty. You could make those values anythimg you like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;infile datalines dsd dlm='^' missover;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input @;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;substr(_infile_,find(_infile_,' '),1) = '^';&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input id :$5. (d1-d5) (:$20.);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;count = countc(_infile_,'^');&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;X1 Fever^Acidity^Vomiting&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;X2 Chills^Nausea&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;X3 Bad Vibes^Bummed^Just Plain Tired&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;X1234 Upset Stomach&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SET: x

id       d1                 d2       d3                  d4    d5    count

X1       Fever            Acidity    Vomiting                          3
X2       Chills           Nausea                                       2
X3       Bad Vibes        Bummed     Just Plain Tired                  3
X1234    Upset Stomach                                                 1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 28 Jul 2017 02:57:15 GMT</pubDate>
    <dc:creator>MikeZdeb</dc:creator>
    <dc:date>2017-07-28T02:57:15Z</dc:date>
    <item>
      <title>Create variables as per separators in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-as-per-separators-in-string/m-p/379431#M91329</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have data as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Subject &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Disease&lt;/P&gt;&lt;P&gt;X1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Fever^Acidity^Vomiting&lt;/P&gt;&lt;P&gt;X2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Chills^Nausea&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need output as below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Subject &amp;nbsp; &amp;nbsp;Disease1 &amp;nbsp; &amp;nbsp; Disease2 &amp;nbsp; &amp;nbsp; &amp;nbsp;Disease3&lt;/P&gt;&lt;P&gt;X1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Fever &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Acidity &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Vomiting&lt;/P&gt;&lt;P&gt;X2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Chills &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Nausea&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We may have more data in Disease column sepearated by ^.I am looking for macro which can count number of ^ in string and create new variables in dataset for each of disease .&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To start with, i have used countc function for occurence of ^ but after that i am not getting any way to move ahead.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone please suggest way forward.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Rajesh&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 15:27:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-as-per-separators-in-string/m-p/379431#M91329</guid>
      <dc:creator>draroda</dc:creator>
      <dc:date>2017-07-26T15:27:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create variables as per separators in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-as-per-separators-in-string/m-p/379435#M91331</link>
      <description>&lt;P&gt;Well, two ways - simplest I find:&lt;/P&gt;
&lt;PRE&gt;data inter;
  set have;
  do i=1 to countw(disease,"^");
    d=scan(disease,i,"^");
    output;
  end;
run;
proc transpose data=inter out=want prefix=disease;
  by subject;
  var d;
run;&lt;/PRE&gt;
&lt;P&gt;You can also find max(count of ^) then use arrays, but thats more code.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 15:32:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-as-per-separators-in-string/m-p/379435#M91331</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-26T15:32:28Z</dc:date>
    </item>
    <item>
      <title>Re: Create variables as per separators in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-as-per-separators-in-string/m-p/379439#M91334</link>
      <description>&lt;P&gt;The "easy" approach might be to just set a large number of variables assuming you'll never exceed that number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data have;
   infile datalines missover;
   informat subject $5. disease $100.;
   input Subject           Disease ;
datalines;
X1 Fever^Acidity^Vomiting
X2 Chills^Nausea
X3 Fever^Acidity^SomethingMuchlonger
;
run;

data want;
   set have;
   array d $30 disease1-disease25;
   do i=1 to (countw(disease,'^'));
      d[i] = scan(disease,i,'^');
   end;
   drop i;
run;
&lt;/PRE&gt;
&lt;P&gt;A possibly more critical issue is actually how long to make your individul "disease" variables (which look more like symptoms). The array I used set them to 30 characters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Execise for the interested reader is to capture the maximum number actually used and then remove unused (hint: retain max i, call symputx and a drop statement in another datastep.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2017 15:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-as-per-separators-in-string/m-p/379439#M91334</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-07-26T15:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: Create variables as per separators in string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-as-per-separators-in-string/m-p/383539#M91482</link>
      <description>&lt;P&gt;Hi, here's another idea. I made the maximum number of diseses five (D1-D5) and the maimum lenght of any disease twenty. You could make those values anythimg you like.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;data x;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;infile datalines dsd dlm='^' missover;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input @;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;substr(_infile_,find(_infile_,' '),1) = '^';&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;input id :$5. (d1-d5) (:$20.);&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;count = countc(_infile_,'^');&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;X1 Fever^Acidity^Vomiting&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;X2 Chills^Nausea&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;X3 Bad Vibes^Bummed^Just Plain Tired&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;X1234 Upset Stomach&lt;/STRONG&gt;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA SET: x

id       d1                 d2       d3                  d4    d5    count

X1       Fever            Acidity    Vomiting                          3
X2       Chills           Nausea                                       2
X3       Bad Vibes        Bummed     Just Plain Tired                  3
X1234    Upset Stomach                                                 1
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 Jul 2017 02:57:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-as-per-separators-in-string/m-p/383539#M91482</guid>
      <dc:creator>MikeZdeb</dc:creator>
      <dc:date>2017-07-28T02:57:15Z</dc:date>
    </item>
  </channel>
</rss>

