<?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: How to go about splitting a column with string values, delimited by commas in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/561989#M17224</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;** let 1=cough, 2=fever, 3=headache, 11=other
** patient #3 has headache and fever;
data have;
	input ID illness$;
	datalines;
	1 1,2
	2 2
	3 3,11
	4 1,2,3,11
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My follow up question was would the countw() function count patient #3 as cough,headache,other instead of just headache,other.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because there is a '1' in '11'. But I just tried the code and it works perfectly!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
    <pubDate>Tue, 28 May 2019 14:54:39 GMT</pubDate>
    <dc:creator>JackyK</dc:creator>
    <dc:date>2019-05-28T14:54:39Z</dc:date>
    <item>
      <title>How to go about splitting a column with string values, delimited by commas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560722#M17174</link>
      <description>&lt;P&gt;Hello all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm pulling table from SQL, say I have a column named "illness":&lt;/P&gt;&lt;PRE&gt;ID | illness
----|---------
1   |  fever,headache
2   |  headache
3   |  cough,fever
4   |  cough,fever,headache&lt;/PRE&gt;&lt;P&gt;In total there are, 4 possible categories (fever, headache, cough, other), how can I go about separating it into 4 columns with 0 or 1 values&lt;/P&gt;&lt;PRE&gt;ID | fever | headache | cough | other 
----|------|----------|-------|---------
1   |  1   |   1      |  0    |    0
2   |  0   |   1      |  0    |    0
3   |  1   |   0      |  1    |    0
4   |  1   |   1      |  1    |    0&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 05:57:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560722#M17174</guid>
      <dc:creator>JackyK</dc:creator>
      <dc:date>2019-05-22T05:57:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to go about splitting a column with string values, delimited by commas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560724#M17175</link>
      <description>&lt;P&gt;Do you need the result as dataset or report?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is one way to create a dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   length id 8 illness $ 100;
   input id illness;
   datalines;
1 fever,headache
2 headache
3 cough,fever
4 cough,fever,headache
;
run;


data want;
   set have;

   length fever headache cough other 8;
   array ill[1:4] fever headache cough other;
   retain illnessList "fever headache cough other";

   do i = 1 to dim(ill);
      ill[i] = 0;
   end;

   do i = 1 to countw(illness, ',');
      p = findw(illnessList, scan(illness, i, ','), ' ', 'itse');
      ill[p] = ill[p] + 1;
   end;

   drop i p illness illnessList;
run;

proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 May 2019 06:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560724#M17175</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-05-22T06:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: How to go about splitting a column with string values, delimited by commas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560756#M17176</link>
      <description>&lt;P&gt;One way to go:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm='|' truncover;
  input id $ illness $30.;
  datalines;
1|fever,headache
2|headache
3|cough,fever
4|cough,fever,headache
4|rash
;

proc sql;
  create table want as
    select
      id,
      find(illness,'fever')&amp;gt;0    as fever,
      find(illness,'headache')&amp;gt;0 as headache,
      find(illness,'cough')&amp;gt;0    as cough,
      max(calculated fever, calculated headache, calculated cough)=0 as other
    from have
    ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 May 2019 10:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560756#M17176</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-22T10:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to go about splitting a column with string values, delimited by commas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560843#M17178</link>
      <description>&lt;P&gt;Hi thank you this is really helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Actually in my data, all the illnesses are coded as numbers. E.g cough=1, fever=2, headache=3, other=11.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So with findw() function, will it pick up 1, even though it's actually 11?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like: if person 5 has 'other'. Will the findw() function read it as 'cough' and 'other'?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 13:55:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560843#M17178</guid>
      <dc:creator>JackyK</dc:creator>
      <dc:date>2019-05-22T13:55:52Z</dc:date>
    </item>
    <item>
      <title>Re: How to go about splitting a column with string values, delimited by commas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560989#M17183</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271262"&gt;@JackyK&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;Actually in my data, all the illnesses are coded as numbers. E.g cough=1, fever=2, headache=3, other=11.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So with findw() function, will it pick up 1, even though it's actually 11?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like: if person 5 has 'other'. Will the findw() function read it as 'cough' and 'other'?&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/271262"&gt;@JackyK&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That sounds like your actual source data looks quite different from what you've posted.&lt;/P&gt;
&lt;P&gt;Can you please provide a SAS data step which creates sample source data as close to what you really have? And then show us the desired result using this sample data.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 23:48:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/560989#M17183</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-05-22T23:48:35Z</dc:date>
    </item>
    <item>
      <title>Re: How to go about splitting a column with string values, delimited by commas</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/561989#M17224</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;** let 1=cough, 2=fever, 3=headache, 11=other
** patient #3 has headache and fever;
data have;
	input ID illness$;
	datalines;
	1 1,2
	2 2
	3 3,11
	4 1,2,3,11
	;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My follow up question was would the countw() function count patient #3 as cough,headache,other instead of just headache,other.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Because there is a '1' in '11'. But I just tried the code and it works perfectly!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2019 14:54:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-go-about-splitting-a-column-with-string-values-delimited/m-p/561989#M17224</guid>
      <dc:creator>JackyK</dc:creator>
      <dc:date>2019-05-28T14:54:39Z</dc:date>
    </item>
  </channel>
</rss>

