<?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 create character variable with three levels based on condition, in SAS 9.4 in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522791#M73451</link>
    <description>&lt;P&gt;Could PovDensity change from county to county, within the same State?&amp;nbsp; (If so, your current logic is incomplete.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the data set MergedTables contain both County and State?&lt;/P&gt;</description>
    <pubDate>Thu, 20 Dec 2018 04:33:27 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2018-12-20T04:33:27Z</dc:date>
    <item>
      <title>How to create character variable with three levels based on condition, in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522790#M73450</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a SAS beginner and have been struggling with the following problem for a few days now. I have a table with 4 variables: State, County, Poverty Density (PovDensity), Median Poverty Density(Median_Poverty_Density) and what I want to do is create a new character variable PovStatus with levels "Above State Median", "Below State Median"and "State Median" depending on whether each county's poverty density is above, below or equal to the state median poverty density. Now, my set contains three States: Alabama, Arkansas and Arizona but each of them has a bunch of different counties. Here is my code so far for Alabama:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Med1;
Set MergedTables;
where state="Alabama";
run;
proc print data=Med1;
run;
data Med2;
set Med1;
if PovDensity&amp;gt;10.287 then 
PovStatus="Above State Median";
else if PovDensity&amp;lt;10.287 then PovStatus="Below State Median";
else if PovDensity=10.287 then PovStatus="State Median";
run;
proc print data=Med2;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It works but I don't think I'm supposed to be doing it like this for each state separately, instead I want something that checks these conditions at once for all three states and gives me the correct results. I would greatly appreciate any feedback/suggestions for how I might achieve that.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 04:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522790#M73450</guid>
      <dc:creator>BankySm</dc:creator>
      <dc:date>2018-12-20T04:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to create character variable with three levels based on condition, in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522791#M73451</link>
      <description>&lt;P&gt;Could PovDensity change from county to county, within the same State?&amp;nbsp; (If so, your current logic is incomplete.)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does the data set MergedTables contain both County and State?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 04:33:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522791#M73451</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-12-20T04:33:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to create character variable with three levels based on condition, in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522793#M73452</link>
      <description>&lt;P&gt;Show the data you have please. Or make fake data that looks close enough.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 04:35:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522793#M73452</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-12-20T04:35:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to create character variable with three levels based on condition, in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522797#M73453</link>
      <description>&lt;P&gt;Why would&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Med;
set MergedTables;
if PovDensity&amp;gt;Median_Poverty_Density then 
PovStatus="Above State Median";
else if PovDensity&amp;lt;Median_Poverty_Density then PovStatus="Below State Median";
else if PovDensity=Median_Poverty_Density then PovStatus="State Median";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;not work?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 05:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522797#M73453</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2018-12-20T05:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to create character variable with three levels based on condition, in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522813#M73454</link>
      <description>&lt;P&gt;You don't need to tell us long stories about your tables, just post them in a data step with datalines. Then we will know everything (Maxim 3) about your existing data (variable names, types, formats, lengths, and content).&lt;/P&gt;
&lt;P&gt;Post what you want to get out of it, so we can then bridge the gap in between with code.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 08:53:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522813#M73454</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-12-20T08:53:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to create character variable with three levels based on condition, in SAS 9.4</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522848#M73455</link>
      <description>&lt;P&gt;Here's an example of what you're trying to do, I think, but using the sample CARS data set.&amp;nbsp; First you need the Median for each class value (State, in your case).&amp;nbsp; Then you need to merge &amp;amp; calculate a new variable based on this categorized value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Calculate median at the category level */
proc summary data=sashelp.cars median;
 class origin;
 var msrp;
 output out=medians median=msrpMedian;
run;

/* Join the detail with the categorized median  */
/* And compute new conditional value using CASE */
proc sql;
 create table Result as 
  select t1.make, t1.model, t1.origin, t1.msrp, t2.msrpMedian,
    case
     when t1.msrp &amp;gt; t2.msrpMedian then "Above Origin Median"
     when t1.msrp = t2.msrpMedian then "At Origin Median"
     when t1.msrp &amp;lt; t2.msrpMedian then "Below Origin Median"
     else "Unknown"
    end as MsrpStatus
  from sashelp.cars t1 left join medians (where=(_type_=1)) t2 
  on t1.origin = t2.origin
  order by model;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="classvar.png" style="width: 600px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/25821i92A8D23F5D6E8413/image-size/large?v=v2&amp;amp;px=999" role="button" title="classvar.png" alt="classvar.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Dec 2018 13:22:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-to-create-character-variable-with-three-levels-based-on/m-p/522848#M73455</guid>
      <dc:creator>ChrisHemedinger</dc:creator>
      <dc:date>2018-12-20T13:22:51Z</dc:date>
    </item>
  </channel>
</rss>

