<?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: Creating multiple variables based on the condition of a single existing variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-variables-based-on-the-condition-of-a-single/m-p/141002#M28350</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is another way of doing it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc tabulate data=have;&lt;/P&gt;&lt;P&gt;class composite ethnic gender college class;&lt;/P&gt;&lt;P&gt;table ethnic*gender*college all='Total',class*N=' ';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 01 May 2014 21:37:21 GMT</pubDate>
    <dc:creator>stat_sas</dc:creator>
    <dc:date>2014-05-01T21:37:21Z</dc:date>
    <item>
      <title>Creating multiple variables based on the condition of a single existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-variables-based-on-the-condition-of-a-single/m-p/141000#M28348</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to get demographic counts from a dataset.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The below example is just a portion of the dataset, but contains most of what I am trying to measure.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;For each section of a class, I want to get the number of the different ethnicities, genders, colleges (to which the student belongs) and classification of the student.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Right now my method is rather "clunky" but it works.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried a combination of arrays and do loops, but it didn't seem to like what I was trying.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for your time.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;length id $2 composite $12 ethnic $1 gender $1 college $2 class $2;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile datalines dlm=',' dsd;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; input id $ composite $ ethnic $ gender $ college $ class $;&lt;/P&gt;&lt;P&gt;return;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;"01","MATH*4583*01",1,"M","AS","FR"&lt;/P&gt;&lt;P&gt;"02","MATH*4583*01",5,"F","AS","SO"&lt;/P&gt;&lt;P&gt;"03","MATH*4583*01",2,"M","HS","JR"&lt;/P&gt;&lt;P&gt;"04","MATH*4583*01",4,"F","PE","SR"&lt;/P&gt;&lt;P&gt;"05","MATH*4583*01",3,"F","N","PB"&lt;/P&gt;&lt;P&gt;"06","MATH*4583*01",6,"M","G","FR"&lt;/P&gt;&lt;P&gt;"07","MATH*4583*01",7,"M","G","FR"&lt;/P&gt;&lt;P&gt;"01","MATH*4583*02",1,"M","AS","FR"&lt;/P&gt;&lt;P&gt;"04","MATH*4583*02",4,"F","PE","SR"&lt;/P&gt;&lt;P&gt;"02","MATH*4583*02",1,"F","AS","SO"&lt;/P&gt;&lt;P&gt;"08","MATH*4583*02",8,"M","N","PB"&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by composite;&lt;/P&gt;&lt;P&gt;run;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*&amp;nbsp;&amp;nbsp;&amp;nbsp; This works, but surely it can be done better&amp;nbsp;&amp;nbsp;&amp;nbsp; */&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; by composite;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.composite then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; section_headcount = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; eth_1 = 0; eth_2 = 0; eth_3 = 0; eth_4 = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; eth_5 = 0; eth_6 = 0; eth_7 = 0; eth_8 = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; m = 0; f = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; as = 0; hs = 0; pe = 0; n = 0; g = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; fr = 0; so = 0; jr = 0; sr = 0; pb = 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; section_headcount + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ethnic = '1' then eth_1 + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ethnic = '2' then eth_2 + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ethnic = '3' then eth_3 + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ethnic = '4' then eth_4 + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ethnic = '5' then eth_5 + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ethnic = '6' then eth_6 + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ethnic = '7' then eth_7 + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if ethnic = '8' then eth_8 + 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gender = 'M' then m + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if gender = 'F' then f + 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if college = 'AS' then as + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if college = 'HS' then hs + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if college = 'PE' then pe + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if college = 'N' then n + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if college = 'G' then g + 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if class = 'FR' then fr + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if class = 'SO' then so + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if class = 'JR' then jr + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if class = 'SR' then sr + 1;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if class = 'PB' then pb + 1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if last.composite;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; drop ethnic id gender college class;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 May 2014 19:07:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-variables-based-on-the-condition-of-a-single/m-p/141000#M28348</guid>
      <dc:creator>GregG</dc:creator>
      <dc:date>2014-05-01T19:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple variables based on the condition of a single existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-variables-based-on-the-condition-of-a-single/m-p/141001#M28349</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you want counts then look to a report procedure. Assuming your variable composite is what you refere to as section of class then&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc freq data = have;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tables composite *( ethnic&amp;nbsp; gender college&amp;nbsp; class) / norow nocol nopercent ;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;might give you what you are looking for.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If you need a dataset then provide how it should look.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 May 2014 20:30:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-variables-based-on-the-condition-of-a-single/m-p/141001#M28349</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-05-01T20:30:13Z</dc:date>
    </item>
    <item>
      <title>Re: Creating multiple variables based on the condition of a single existing variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-variables-based-on-the-condition-of-a-single/m-p/141002#M28350</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is another way of doing it&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc tabulate data=have;&lt;/P&gt;&lt;P&gt;class composite ethnic gender college class;&lt;/P&gt;&lt;P&gt;table ethnic*gender*college all='Total',class*N=' ';&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 01 May 2014 21:37:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-multiple-variables-based-on-the-condition-of-a-single/m-p/141002#M28350</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-05-01T21:37:21Z</dc:date>
    </item>
  </channel>
</rss>

