<?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: Keeping all variables and put zero when variables are blank in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777413#M247319</link>
    <description>If all categories are in your data somehow you can use the SPARSE option which builds 'full' tables.&lt;BR /&gt;&lt;BR /&gt;tables RACEGP*AGEGP1*SEXGP/out=TEST_totall sparse;&lt;BR /&gt;&lt;BR /&gt;If you have more complex situation then you need to use a PRELOADFMT, I'll let you google that one. Tons of examples on here.&lt;BR /&gt;</description>
    <pubDate>Fri, 29 Oct 2021 20:40:49 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-10-29T20:40:49Z</dc:date>
    <item>
      <title>Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777408#M247316</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a SAS program that is reading in death(mortality) data by age and I created the following code for five age groups:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;IF AGE GE 0 AND AGE lt 17 THEN AGEGP1="0-17";&lt;BR /&gt;ELSE IF 18&amp;lt;=AGE&amp;lt;=29 THEN AGEGP1="18-29";&lt;BR /&gt;ELSE IF 30&amp;lt;=AGE&amp;lt;=44 THEN AGEGP1="30-44";&lt;BR /&gt;ELSE IF 45&amp;lt;=AGE&amp;lt;=64 THEN AGEGP1="45-64";&lt;BR /&gt;ELSE IF AGE ge 65 THEN AGEGP1="65+";&lt;/P&gt;&lt;P&gt;ELSE AGEGP1=" ";&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;Next,&amp;nbsp; I run the following Proc Freq:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;proc freq data=deaths_&amp;amp;year. noprint;&lt;BR /&gt;tables RACEGP*AGEGP1*SEXGP/out=TEST_totall;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;I know I wouldn't see any deaths for example in "Alzheimers Disease"&amp;nbsp; in the younger age groups(0-17, 18-29, 30-44), therefore they wouldn't show in the output dataset.&amp;nbsp; However,&amp;nbsp; I want to keep all of the age groups in the output dataset and assign 0 to the age groups that don't have any observations for a given cause of death.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: inherit;"&gt;My final output dataset should display all 5 of the age groups.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;Can anyone please advise or suggest how to code for this?&amp;nbsp; Thanks.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 20:31:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777408#M247316</guid>
      <dc:creator>Chgo5</dc:creator>
      <dc:date>2021-10-29T20:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777413#M247319</link>
      <description>If all categories are in your data somehow you can use the SPARSE option which builds 'full' tables.&lt;BR /&gt;&lt;BR /&gt;tables RACEGP*AGEGP1*SEXGP/out=TEST_totall sparse;&lt;BR /&gt;&lt;BR /&gt;If you have more complex situation then you need to use a PRELOADFMT, I'll let you google that one. Tons of examples on here.&lt;BR /&gt;</description>
      <pubDate>Fri, 29 Oct 2021 20:40:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777413#M247319</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-29T20:40:49Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777415#M247320</link>
      <description>&lt;P&gt;Tried the Sparse and it didn't keep all the age groups.&amp;nbsp; I will lookup the PRELOADFMT and see how that works.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 20:47:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777415#M247320</guid>
      <dc:creator>Chgo5</dc:creator>
      <dc:date>2021-10-29T20:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777417#M247321</link>
      <description>COMPLETETYPES is the other option. &lt;BR /&gt;FYI - if sparse didn't work that means you'll have a few age groups that have 0 throughout your data for all diseases/categories.</description>
      <pubDate>Fri, 29 Oct 2021 20:52:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777417#M247321</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-29T20:52:37Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777419#M247322</link>
      <description>&lt;P&gt;By creating a new variable named AGEGRP1, PROC FREQ (even with the SPARSE option) only knows about the levels in the actual data set, and if a level doesn't appear in the data set, then PROC FREQ can't find it and put it in the table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of creating a new variable named AGEGRP1, you can create a custom format and then apply this custom format to variable AGE. Then PROC FREQ, with the SPARSE option, should give the desired output.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think PROC FREQ has COMPLETETYPES or PRELOADFMT options; however PROC SUMMARY does have these and could also work here if the proper format is applied.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 21:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777419#M247322</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-10-29T21:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777421#M247323</link>
      <description>Added benefit of using a format, your age categories usually sort correctly by default then which becomes important later on &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 29 Oct 2021 21:13:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777421#M247323</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-10-29T21:13:51Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777493#M247366</link>
      <description>&lt;P&gt;If you have already completed the PROC FREQ,&amp;nbsp; you could build upon it to create the complete set of categories.&amp;nbsp; For example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table races as select distinct racegp from test_totall;
   create table ages as select distinct agegp1 from test_totall;
   create table genders as select distinct sexgp from test_totall;
   create table complete_shell as select * from races, ages, genders;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This gives you a complete set of all combinations of your variables, with no counts filled in.&amp;nbsp; It could be sorted and merged with TEST_totall and the observations with a missing COUNT could be set to 0 at that point.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also note, the AGEGP1 might be missing a character from the end.&amp;nbsp; The first value you set is "0-17" which is four characters long.&amp;nbsp; That means all the values will be four characters long, missing the fifth character.&amp;nbsp; So before all the logic you posted, you should add:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length agegp1 $ 5;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 30 Oct 2021 11:14:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777493#M247366</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-10-30T11:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777773#M247508</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've actually tried all of the suggestions including yours &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;and I'm still not getting the desired output. For example, I'm selecting for cervical cancer deaths for Chicago by the 5 age groups.&amp;nbsp; In my dataset, the age groups '0-17'&amp;nbsp; and '18-29'&amp;nbsp; are missing because there are no cervical cancer deaths in these age groups.&amp;nbsp; I basically need to figured how to keep/include the age groups even though they don't exist.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 01 Nov 2021 20:44:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777773#M247508</guid>
      <dc:creator>Chgo5</dc:creator>
      <dc:date>2021-11-01T20:44:43Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777780#M247515</link>
      <description>&lt;P&gt;Here's an example of how to do this using SASHELP.CLASS.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
    value agef 0-10='0-10' 11-12='11-12' 13-14='13-14' 15-high='&amp;gt;15';
run;
data class;
    set sashelp.class;
    format age agef.;
run;
proc summary data=class completetypes nway;
    class age/preloadfmt;
    format age agef.;
    var height;
    output out=n n=n;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 Nov 2021 21:15:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777780#M247515</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-11-01T21:15:24Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777791#M247525</link>
      <description>Show what you've tried with either CLASSDATA or PRELOADFMT please.</description>
      <pubDate>Mon, 01 Nov 2021 22:03:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777791#M247525</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-11-01T22:03:05Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777931#M247594</link>
      <description>&lt;P&gt;You can create a complete set of cells by going back to your original data and using that as the input to PROC SQL.&amp;nbsp; So that would not depend on any medical conditions.&amp;nbsp; The only way a category would be omitted is if it does not occur at all in the data, for any medical conditions.&amp;nbsp; As long as it occurs at least once for any medical condition, it would be included.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 14:39:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777931#M247594</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-11-02T14:39:32Z</dc:date>
    </item>
    <item>
      <title>Re: Keeping all variables and put zero when variables are blank</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777978#M247615</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Thanks for the code.&amp;nbsp; I was able to keep all of the age groups.&amp;nbsp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;Here is what the code looks like:&lt;/P&gt;&lt;P&gt;PROC FORMAT;&lt;/P&gt;&lt;P&gt;VALUE $AGEGPP&lt;BR /&gt;' 0' - ' 17' = '0-17'&lt;BR /&gt;' 18'-' 29' = '18-29'&lt;BR /&gt;' 30'-' 44' = '30-44'&lt;BR /&gt;' 45'-' 64' = '45-64'&lt;BR /&gt;OTHER = '65+';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc summary data=deaths_&amp;amp;year. completetypes nway;&lt;BR /&gt;class racegp AGEGP1 sexgp/preloadfmt;&lt;BR /&gt;format AGEGP1 $AGEGPP.;&lt;BR /&gt;output out=TEST_totall;* n=n;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Nov 2021 17:41:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keeping-all-variables-and-put-zero-when-variables-are-blank/m-p/777978#M247615</guid>
      <dc:creator>Chgo5</dc:creator>
      <dc:date>2021-11-02T17:41:07Z</dc:date>
    </item>
  </channel>
</rss>

