<?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: Convert character variable to numerical (LARGE dataset, many different values) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654096#M196499</link>
    <description>&lt;P&gt;what will this do:&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;retain drugNum 0;

if first.drugName then drugNum+1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do is a cox proportional hazards model, and I may need to adjust for contraceptive use, hormone therapy, and menopause treatment--but in order to know if this is necessary I first need a count of how many of each drug there is, and then I need to group these.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ie group together all the types of contraceptives, and then count #contraceptives&lt;/P&gt;&lt;P&gt;same with hormone therapy, and the other variables I'll create.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not know exactly how many different values there are, but they are consistently named&lt;/P&gt;</description>
    <pubDate>Mon, 08 Jun 2020 03:18:31 GMT</pubDate>
    <dc:creator>Student77</dc:creator>
    <dc:date>2020-06-08T03:18:31Z</dc:date>
    <item>
      <title>Convert character variable to numerical (LARGE dataset, many different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654085#M196489</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large dataset (~30,000 obs).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a variable called prescriptions, and there are many many different options. In order to adjust for certain drugs in my model I need to convert these to numerical. I also need to get a count of how many of each drug there is to see if it is worth adjusting for anyway.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a quick/easy way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would hate to go one by one:&lt;/P&gt;&lt;P&gt;if drug="atorvastatin" then numdrug=1;&lt;/P&gt;&lt;P&gt;if ...etc for hundreds of drugs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 02:05:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654085#M196489</guid>
      <dc:creator>Student77</dc:creator>
      <dc:date>2020-06-08T02:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to numerical (LARGE dataset, many different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654087#M196491</link>
      <description>&lt;P&gt;Depends on your data and what you're trying to do. Why do you think you need to convert them to numeric values to start off?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the drugs are consistently named you can sort and arbitrarily number them quite easily. If they are not consistently named then you have a more complicated problem.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by drugName;
run;

data want;
set have;

by drugName;
retain drugNum 0;

if first.drugName then drugNum+1;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;FYI - 30k records is not a large dataset. &amp;nbsp;The number of observations doesn't change the approach in this situation, but the number of drugs will.&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/332727"&gt;@Student77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a large dataset (~30,000 obs).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a variable called prescriptions, and there are many many different options. In order to adjust for certain drugs in my model I need to convert these to numerical. I also need to get a count of how many of each drug there is to see if it is worth adjusting for anyway.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is there a quick/easy way?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would hate to go one by one:&lt;/P&gt;
&lt;P&gt;if drug="atorvastatin" then numdrug=1;&lt;/P&gt;
&lt;P&gt;if ...etc for hundreds of drugs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 02:39:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654087#M196491</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-08T02:39:37Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to numerical (LARGE dataset, many different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654096#M196499</link>
      <description>&lt;P&gt;what will this do:&lt;/P&gt;&lt;PRE class="language-sas"&gt;&lt;CODE&gt;retain drugNum 0;

if first.drugName then drugNum+1;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I am trying to do is a cox proportional hazards model, and I may need to adjust for contraceptive use, hormone therapy, and menopause treatment--but in order to know if this is necessary I first need a count of how many of each drug there is, and then I need to group these.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ie group together all the types of contraceptives, and then count #contraceptives&lt;/P&gt;&lt;P&gt;same with hormone therapy, and the other variables I'll create.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I do not know exactly how many different values there are, but they are consistently named&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 03:18:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654096#M196499</guid>
      <dc:creator>Student77</dc:creator>
      <dc:date>2020-06-08T03:18:31Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to numerical (LARGE dataset, many different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654097#M196500</link>
      <description>&lt;P&gt;30,000 observations is a (very) small data set.&lt;/P&gt;
&lt;P&gt;Without actual data examples, it's hard to give better code than&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;'s.&lt;/P&gt;
&lt;P&gt;How do we know a drug is a contraceptive, and what should the output look like?&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 03:27:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654097#M196500</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2020-06-08T03:27:22Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to numerical (LARGE dataset, many different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654103#M196505</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/332727"&gt;@Student77&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;what will this do:&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;retain drugNum 0;

if first.drugName then drugNum+1;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It creates a enumerator for your drugs which is what you've asked for. How this works is explained &lt;A href="https://stats.idre.ucla.edu/sas/faq/how-can-i-create-an-enumeration-variable-by-groups/" target="_self"&gt;here&lt;/A&gt; and &lt;A href="https://blogs.sas.com/content/iml/2018/02/26/how-to-use-first-variable-and-last-variable-in-a-by-group-analysis-in-sas.html" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Jun 2020 04:30:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654103#M196505</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-06-08T04:30:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert character variable to numerical (LARGE dataset, many different values)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654534#M196548</link>
      <description>Sounds like you'll need to recode your drugs then. Do you have a master table of which drugs belong to which groups? If so, you can either join to that table or create a format (slightly more efficient) and then do your analysis. &lt;BR /&gt;&lt;BR /&gt;You can also create that table manually if you don't have it to save yourself time. That's probably the recommend route at this point. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 08 Jun 2020 14:04:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-character-variable-to-numerical-LARGE-dataset-many/m-p/654534#M196548</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2020-06-08T14:04:47Z</dc:date>
    </item>
  </channel>
</rss>

