<?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: Continuous variable into categories dynamically? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141297#M37702</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Astounding, thank you, that was the solution I needed.&amp;nbsp; Now I can even make a macro to handle it easily.&amp;nbsp; I have only recently become acquainted with the if _n_=1 kind of statement, but I see much future use for it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paige, I had tried proc rank with the group option.&amp;nbsp; However, it seemed that proc rank wanted to force a certain number of observations into each group, rather than assign the group (bin) based on the value of my continuous variable.&amp;nbsp; And I agree that this seems like a somewhat backwards/extraneous was of analyzing a variable, however, we are working with a group that does not "believe" our models, and we have to break the math down into it's component steps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reeza, I had tried proc format, but with groupings like &amp;gt; x- &amp;lt;=y I got errors in proc format.&amp;nbsp; It did not seem to like the &amp;gt; in front of the range.&amp;nbsp; Maybe I could have changed my logic to make it work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you all.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Sep 2014 13:46:59 GMT</pubDate>
    <dc:creator>NWV</dc:creator>
    <dc:date>2014-09-12T13:46:59Z</dc:date>
    <item>
      <title>Continuous variable into categories dynamically?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141293#M37698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have continuous data in a variable that looks like the attached text file.&amp;nbsp; Sorry, I cannot paste anything into this forum box.&amp;nbsp; If anyone knows why, please tell me! Too much to do in the html editor&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am dividing it into 20 groups, based on the percentiles.&amp;nbsp; I use proc univariate to get the percentiles:&lt;/P&gt;&lt;P&gt;proc univariate data=d1 ;&lt;/P&gt;&lt;P&gt;var X;&lt;/P&gt;&lt;P&gt;output out=getpercentiles pctlpre=P_ pctlpts=5 to 100 by 5;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want the resulting percentiles to be the top of the categories.&amp;nbsp; I then write if/then statements to categorize my original data:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if X ge 0 and LTCumExpT2 le 0.019 then bin=1;*note, lowest category starts at 0;&lt;/P&gt;&lt;P&gt;else if X gt 0.019 and X le 0.038 then bin=2;&lt;/P&gt;&lt;P&gt;else if X gt 0.038 and X le 0.078 then bin=3;&lt;/P&gt;&lt;P&gt;else if X gt 0.078 and X le 0.095 then bin=4;&lt;/P&gt;&lt;P&gt;else if X gt 0.095 and X le 0.1265 then bin=5;&lt;/P&gt;&lt;P&gt;else if X gt 0.1265 and X le 0.166 then bin=6;&lt;/P&gt;&lt;P&gt;else if X gt 0.166 and X le 0.254 then bin=7;&lt;/P&gt;&lt;P&gt;....&lt;/P&gt;&lt;P&gt;else if X gt 8.088 and X le 34.435 then bin=20;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is there a way to get a new variable "bin" with a number from 1 to 20 in it more dynamically?&amp;nbsp; Rather than having to create all those if then statements?&amp;nbsp; I have searched the forums, and most people say to use a format, but that can't be done here, with the gt/le operators, as far as I can tell (trust me, I tried :smileygrin:).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If it was just the one variable I had to do this for, I wouldn't mind.&amp;nbsp; But I have to do it for about 20 of them, and was hoping to make it more painless.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Nicole&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 19:45:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141293#M37698</guid>
      <dc:creator>NWV</dc:creator>
      <dc:date>2014-09-11T19:45:25Z</dc:date>
    </item>
    <item>
      <title>Re: Continuous variable into categories dynamically?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141294#M37699</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think PROC RANK with the GROUPS= option can do what you want.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As a side issue, I question the value of performing a statistical analysis on percentiles of continuous data, when you could perform an equivalent analysis on the raw continuous data.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 20:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141294#M37699</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2014-09-11T20:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: Continuous variable into categories dynamically?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141295#M37700</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You can paste data with a browser other than IE. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can do this with a format, but I agree with Paige, Proc Rank is better option.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For format creation see this paper:&lt;/P&gt;&lt;P&gt;&lt;A href="http://www2.sas.com/proceedings/forum2007/068-2007.pdf" title="http://www2.sas.com/proceedings/forum2007/068-2007.pdf"&gt;http://www2.sas.com/proceedings/forum2007/068-2007.pdf&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 21:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141295#M37700</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-09-11T21:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Continuous variable into categories dynamically?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141296#M37701</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have all the pieces you need.&amp;nbsp; There is no need to type, just put the pieces together.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may need to tweak this a little bit, but here is the idea (using the names for data sets and variables that appear in your example):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if _n_=1 then set getpercentiles;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set d1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; if x &amp;gt; P_20 then bin=20;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if x &amp;gt; P_19 then bin=19;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if x &amp;gt; P_18 then bin=18;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else if x &amp;gt; P_2 then bin=2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; else bin=1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; drop P_:;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You may need to reverse the order, or change the comparisons slightly.&amp;nbsp; But all the pieces are there and you only have to assemble them into the same data set. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you have to do this for 20 variables, you may want to use different prefixes in the output data sets for each.&amp;nbsp; But first, figure out how to do it for one variable without typing in the cutoffs.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is not a comment about which solution is best, only an answer to your original question.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 21:14:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141296#M37701</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2014-09-11T21:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: Continuous variable into categories dynamically?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141297#M37702</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Astounding, thank you, that was the solution I needed.&amp;nbsp; Now I can even make a macro to handle it easily.&amp;nbsp; I have only recently become acquainted with the if _n_=1 kind of statement, but I see much future use for it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Paige, I had tried proc rank with the group option.&amp;nbsp; However, it seemed that proc rank wanted to force a certain number of observations into each group, rather than assign the group (bin) based on the value of my continuous variable.&amp;nbsp; And I agree that this seems like a somewhat backwards/extraneous was of analyzing a variable, however, we are working with a group that does not "believe" our models, and we have to break the math down into it's component steps.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Reeza, I had tried proc format, but with groupings like &amp;gt; x- &amp;lt;=y I got errors in proc format.&amp;nbsp; It did not seem to like the &amp;gt; in front of the range.&amp;nbsp; Maybe I could have changed my logic to make it work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you all.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2014 13:46:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141297#M37702</guid>
      <dc:creator>NWV</dc:creator>
      <dc:date>2014-09-12T13:46:59Z</dc:date>
    </item>
    <item>
      <title>Re: Continuous variable into categories dynamically?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141298#M37703</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I sympathize with your problems regarding the categorization of continuous variables.&amp;nbsp; For my own peace of mind, I would analyze both ways--a great way to make a problem (=adverse event rate) "disappear" is to categorize the continuous covariates or continuous response variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Steve Denham&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Sep 2014 16:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Continuous-variable-into-categories-dynamically/m-p/141298#M37703</guid>
      <dc:creator>SteveDenham</dc:creator>
      <dc:date>2014-09-12T16:35:58Z</dc:date>
    </item>
  </channel>
</rss>

