<?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: Adding the missing categories for which the attendance was 0 in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801587#M315470</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;Thanks a lot. This is exactly what I was looking for. Could not have accomplished it without your help as I am pretty new to sas with zero experience of proc sql. Thanks again.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 11 Mar 2022 03:43:34 GMT</pubDate>
    <dc:creator>Novice_</dc:creator>
    <dc:date>2022-03-11T03:43:34Z</dc:date>
    <item>
      <title>Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801430#M315416</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a huge aggregate dataset that shows the number of people attending an event from different companies by year, age-group and gender. If no one from a particular age-group and gender attended then that row is missing. I want all the nested categories for each year with number attending = 0 for the ones missing here. Currently my data looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Novice__0-1646936948998.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69354i53A89B4867F9F411/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Novice__0-1646936948998.png" alt="Novice__0-1646936948998.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I want it to look like below. For each company and year I want to have the complete set of age and gender combinations attended taking a value of 0 for those missing in the data above.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Novice__1-1646937126568.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69355iC49E74D62DEC02D5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Novice__1-1646937126568.png" alt="Novice__1-1646937126568.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I will highly appreciate if I can be helped with this. Thank you.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:34:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801430#M315416</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-10T18:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801431#M315417</link>
      <description>&lt;P&gt;This is relatively easy when you create a report or table. So, does it really have to be that this is done in a data set? Or can it be done when the report/table is created?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 18:36:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801431#M315417</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-10T18:36:39Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801472#M315425</link>
      <description>&lt;P&gt;Can it be done in the data because I have to merge this data with another that has total number of employees in all companies for each year by complete age_group (shown here) and gender i.e.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Novice__0-1646940667005.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69361i0E5951459C9CE5CD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Novice__0-1646940667005.png" alt="Novice__0-1646940667005.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;and I have to merge by year age_group and gender to the attendance data by each company. There wouldn't be a problem if I have this total employees by company as well. Thanks&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 19:34:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801472#M315425</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-10T19:34:15Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801474#M315426</link>
      <description>&lt;P&gt;It can be done when the merge happens. Something like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     merge dataset1 dataset2;
     by year age gender;
     if missing(attended) then attended=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Always a good thing to mention all the facts of the situation in your first message, rather than not mentioning relevant facts until someone asks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 19:45:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801474#M315426</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-10T19:45:47Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801563#M315456</link>
      <description>&lt;P&gt;I am sorry merging them like you said does not give me the correct results. Please see below, I do not see company A 2013 19-29 female, company A 2013 40-49 male, company B 2012 19-29 female and company B 2012 40-49 female&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Novice__0-1646959367707.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69389iF7A83D570FFEFE5F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Novice__0-1646959367707.png" alt="Novice__0-1646959367707.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Is there a way to have complete categories in attendance data before merging? Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 00:48:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801563#M315456</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-11T00:48:00Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801565#M315458</link>
      <description>&lt;P&gt;Something like this should populate the missing company values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
     merge dataset1 dataset2;
     by year age gender;
     if missing(attended) then attended=0;
run;

proc sort data = want;
  by descending company year age gender;
run;

data want2;
  set want;
  by descending company year age gender;
  retain Current_Company;
  if first.company then Current_Company = company;
  else if missing(company) then company = Current_Company;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2022 01:22:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801565#M315458</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-03-11T01:22:56Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801573#M315460</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp;thanks a lot for the code but unfortunately it is not working. I am getting the following:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Novice__0-1646965417757.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69393i68973B8710A70A5B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Novice__0-1646965417757.png" alt="Novice__0-1646965417757.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 02:23:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801573#M315460</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-11T02:23:53Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801577#M315461</link>
      <description>&lt;P&gt;SQL cross joins provide you with the cartesian product (all combinations) of categories:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want AS
select 
    a.company,
    b.year,
    c.age,
    d.gender,
    coalesce(e.attended, 0) as attended
from 
    (select distinct company from have) as a cross join
    (select distinct year from have) as b cross join
    (select distinct age from have) as c cross join
    (select distinct gender from have) as d left join
    have as e 
        on a.company=e.company and b.year=e.year and 
            c.age=e.age and d.gender=e.gender;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;(untested)&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 02:34:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801577#M315461</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-03-11T02:34:05Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801578#M315462</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393584"&gt;@Novice_&lt;/a&gt;&amp;nbsp;- Since you didn't provide any data in a suitable form (you can't copy and paste screenshots) I'm unable to test a solution.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;method is better but you need to provide test data using a DATA step with DATALINES for a working solution to be provided.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 02:48:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801578#M315462</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-03-11T02:48:14Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801586#M315469</link>
      <description>&lt;P&gt;I am sorry about not providing the data earlier. Please see below;&lt;/P&gt;&lt;P&gt;This is the data that I have (its only the data from two companies and the original has a lot of companies):&lt;/P&gt;&lt;P&gt;data have;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input company $ year age $ gender $ attended;&lt;BR /&gt;cards;&lt;BR /&gt;A 2012 19-29 Male 12&lt;BR /&gt;A 2012 19-29 Female 10&lt;BR /&gt;A 2012 30-39 Male 7&lt;BR /&gt;A 2012 30-39 Female 5&lt;BR /&gt;A 2012 40-49 Male 14&lt;BR /&gt;A 2012 40-49 Female 32&lt;BR /&gt;A 2012 50+ Male 11&lt;BR /&gt;A 2012 50+ Female 8&lt;BR /&gt;A 2013 19-29 Male 3&lt;BR /&gt;A 2013 30-39 Male 7&lt;BR /&gt;A 2013 30-39 Female 2&lt;BR /&gt;A 2013 40-49 Female 6&lt;BR /&gt;A 2013 50+ Male 3&lt;BR /&gt;A 2013 50+ Female 4&lt;BR /&gt;B 2012 19-29 Male 2&lt;BR /&gt;B 2012 30-39 Male 5&lt;BR /&gt;B 2012 30-39 Female 7&lt;BR /&gt;B 2012 40-49 Male 5&lt;BR /&gt;B 2013 30-39 Male 3&lt;BR /&gt;B 2013 30-39 Female 5&lt;BR /&gt;B 2013 40-49 Male 8&lt;BR /&gt;B 2013 40-49 Female 2&lt;BR /&gt;B 2013 50+ Male 6&lt;BR /&gt;B 2013 50+ Female 5&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;And before doing anything else with it, I want to have all the year age and gender combinations for each company. This would give me a zero value for the combinations missing above. It should look like below:&lt;/P&gt;&lt;P&gt;A 2012 19-29 Male 12&lt;BR /&gt;A 2012 19-29 Female 10&lt;BR /&gt;A 2012 30-39 Male 7&lt;BR /&gt;A 2012 30-39 Female 5&lt;BR /&gt;A 2012 40-49 Male 14&lt;BR /&gt;A 2012 40-49 Female 32&lt;BR /&gt;A 2012 50+ Male 11&lt;BR /&gt;A 2012 50+ Female 8&lt;BR /&gt;A 2013 19-29 Male 3&lt;BR /&gt;A 2013 19-29 Female 0&lt;BR /&gt;A 2013 30-39 Male 7&lt;BR /&gt;A 2013 30-39 Female 2&lt;BR /&gt;A 2013 40-49 Male 0&lt;BR /&gt;A 2013 40-49 Female 6&lt;BR /&gt;A 2013 50+ Male 3&lt;BR /&gt;A 2013 50+ Female 4&lt;BR /&gt;B 2012 19-29 Male 2&lt;BR /&gt;A 2012 19-29 Female 0&lt;BR /&gt;B 2012 30-39 Male 5&lt;BR /&gt;B 2012 30-39 Female 7&lt;BR /&gt;B 2012 40-49 Male 5&lt;BR /&gt;B 2012 40-49 Female 0&lt;BR /&gt;B 2012 50+ Male 0&lt;BR /&gt;B 2012 50+ Female 0&lt;BR /&gt;B 2013 19-29 Male 0&lt;BR /&gt;B 2013 19-20 Male 0&lt;BR /&gt;B 2013 30-39 Male 3&lt;BR /&gt;B 2013 30-39 Female 5&lt;BR /&gt;B 2013 40-49 Male 8&lt;BR /&gt;B 2013 40-49 Female 2&lt;BR /&gt;B 2013 50+ Male 6&lt;BR /&gt;B 2013 50+ Female 5&lt;/P&gt;&lt;P&gt;I want it to look like above so that I can easily merge it with the following data that has complete combinations of year age and gender&lt;/P&gt;&lt;P&gt;data tomerge;&lt;BR /&gt;infile datalines;&lt;BR /&gt;input year age $ gender $ employees;&lt;BR /&gt;cards;&lt;BR /&gt;2012 19-29 Male 215&lt;BR /&gt;2012 19-29 Female 263&lt;BR /&gt;2012 30-39 Male 271&lt;BR /&gt;2012 30-39 Female 273&lt;BR /&gt;2012 40-49 Male 245&lt;BR /&gt;2012 40-49 Female 165&lt;BR /&gt;2012 50+ Male 237&lt;BR /&gt;2012 50+ Female 186&lt;BR /&gt;2013 19-29 Male 192&lt;BR /&gt;2013 19-29 Female 154&lt;BR /&gt;2013 30-39 Male 176&lt;BR /&gt;2013 30-39 Female 231&lt;BR /&gt;2013 40-49 Male 188&lt;BR /&gt;2013 40-49 Female 176&lt;BR /&gt;2013 50+ Male 134&lt;BR /&gt;2013 50+ Female 201&lt;BR /&gt;;&lt;/P&gt;&lt;P&gt;I hope it is more clear now.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 03:38:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801586#M315469</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-11T03:38:15Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801587#M315470</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;Thanks a lot. This is exactly what I was looking for. Could not have accomplished it without your help as I am pretty new to sas with zero experience of proc sql. Thanks again.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 03:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801587#M315470</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-11T03:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801642#M315505</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc freq data=have noprint;
table company*year*gender / out=want sparse;
weight attended;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 11 Mar 2022 11:59:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801642#M315505</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-03-11T11:59:06Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801700#M315529</link>
      <description>Unfortunately, this dose not give me the required output.</description>
      <pubDate>Fri, 11 Mar 2022 16:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801700#M315529</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-11T16:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801712#M315534</link>
      <description>&lt;P&gt;Try adding &lt;EM&gt;age&lt;/EM&gt; to the table statement in &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt; suggestion. It should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;table company*year*age*gender / out=want sparse;
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 17:44:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801712#M315534</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2022-03-11T17:44:04Z</dc:date>
    </item>
    <item>
      <title>Re: Adding the missing categories for which the attendance was 0</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801714#M315535</link>
      <description>OMG it actually did. Thank you &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 11 Mar 2022 17:58:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Adding-the-missing-categories-for-which-the-attendance-was-0/m-p/801714#M315535</guid>
      <dc:creator>Novice_</dc:creator>
      <dc:date>2022-03-11T17:58:08Z</dc:date>
    </item>
  </channel>
</rss>

