<?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 from multiple character text in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695305#M212165</link>
    <description>&lt;P&gt;Thank you I always forget the going from wide to long step, you're right. You've really helped my day, thanks so much!&lt;/P&gt;</description>
    <pubDate>Thu, 29 Oct 2020 18:35:35 GMT</pubDate>
    <dc:creator>stancemcgraw</dc:creator>
    <dc:date>2020-10-29T18:35:35Z</dc:date>
    <item>
      <title>Create variables from multiple character text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695266#M212145</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Hi all,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; I have a variable called drugs found, and it's in character text with a lot of text per line.&amp;nbsp;I'd like a count of each type of drug found per ID.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Data have;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;studyid &amp;nbsp; &amp;nbsp; &amp;nbsp;drugs_found&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;5 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Methamphine, amphetamines, cocaine&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; none&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;THC&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;studyid &amp;nbsp; &amp;nbsp; &amp;nbsp; Methamphine &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Cannabis &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Amphetamines &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Cocaine &amp;nbsp; &amp;nbsp; &amp;nbsp; No_drugs&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;6 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;7 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 16:41:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695266#M212145</guid>
      <dc:creator>stancemcgraw</dc:creator>
      <dc:date>2020-10-29T16:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create variables from multiple character text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695276#M212150</link>
      <description>&lt;P&gt;I don't see "Cannabis" in the input data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, are these drugs in the input data always going to be spelled identically each time? Do you know in advance what the possible drugs are, or does the program have to figure it out? Does the final table always have values zero and 1, or could there be integers 2, 3, ...?&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 17:11:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695276#M212150</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-29T17:11:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create variables from multiple character text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695279#M212153</link>
      <description>&lt;P&gt;It says THC in the input data, thus I wanted it recorded as CANNABIS and yes, I'd like it to be recorded as dummy variables with 0 and 1.&lt;/P&gt;&lt;P&gt;&amp;nbsp;I included a screenshot of what it looks like, because it does not always look the same and some of the words are cut-off.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 17:17:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695279#M212153</guid>
      <dc:creator>stancemcgraw</dc:creator>
      <dc:date>2020-10-29T17:17:11Z</dc:date>
    </item>
    <item>
      <title>Re: Create variables from multiple character text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695280#M212154</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/78398"&gt;@stancemcgraw&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;It says THC in the input data, thus I wanted it recorded as CANNABIS and yes, I'd like it to be recorded as dummy variables with 0 and 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;I included a screenshot of what it looks like, because it does not always look the same and some of the words are cut-off.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Ok, thank you, but I asked other questions that you didn't answer.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 17:19:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695280#M212154</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-29T17:19:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create variables from multiple character text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695283#M212156</link>
      <description>I don't understand what you mean by, do I know in advance what the possible drugs are? And no, they will not be spelled the exact same way each time. Take a look at the screenshot and you can see all the different iterations...</description>
      <pubDate>Thu, 29 Oct 2020 17:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695283#M212156</guid>
      <dc:creator>stancemcgraw</dc:creator>
      <dc:date>2020-10-29T17:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Create variables from multiple character text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695300#M212163</link>
      <description>&lt;P&gt;1. Split into a long format using SCAN()&lt;BR /&gt;2. Use previously shown methods, from your recent questions, to transpose and create your indicators. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile cards dlm='09'x;
length drugs_found $50.;
input studyid  $    drugs_found $;
cards;
5	Methamphine, amphetamines, cocaine
6	none
7	THC
;;;;
run;


data long;
set have;

nTerms = countw(drugs_found) ;

do i=1 to nTerms;
word = scan(drugs_found, i, ",");
put word;
if word in ("THC", "CBD") then word = "Cannabis";
else if word in ("none") then call missing(word);
output;
end;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Now use the similar methods shown. If you need to recode values, ie THC/CBD to Cannabis you can add that in the data step above and then transpose your data.&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 18:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695300#M212163</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-10-29T18:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Create variables from multiple character text</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695305#M212165</link>
      <description>&lt;P&gt;Thank you I always forget the going from wide to long step, you're right. You've really helped my day, thanks so much!&lt;/P&gt;</description>
      <pubDate>Thu, 29 Oct 2020 18:35:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-variables-from-multiple-character-text/m-p/695305#M212165</guid>
      <dc:creator>stancemcgraw</dc:creator>
      <dc:date>2020-10-29T18:35:35Z</dc:date>
    </item>
  </channel>
</rss>

