<?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 simulate 'PRELOADFMT' in FREQ , SQL in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864102#M341272</link>
    <description>&lt;P&gt;Maybe use one of the procedures that uses preloadfmt to create an output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you show what you actually expect for output? If you expect a missing for each for each age that can be done in Sql be creating an output set from the Proc Format code and joining that with the data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format out=work.shffmt;
      value $shf 'F'= 'Female'
                'M'= 'Male'
                'U' = 'Missing';
   select $shf;
quit;

proc sql;
     create table cnt1 as
     select b.start as sex format $shf.,age, count(*) as cnt 
     from sashelp.class as a
          ,work.shffmt as b
         group by b.start,age;
quit;&lt;/PRE&gt;
&lt;P&gt;But that gets very cumbersome if you want to do this for multiple variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Mar 2023 16:11:49 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-03-14T16:11:49Z</dc:date>
    <item>
      <title>How to simulate 'PRELOADFMT' in FREQ , SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864076#M341260</link>
      <description>&lt;P&gt;I recently learned about using PRELOADFMT in MEANS, SUMMARY, and REPORT procedures. Can I achieve this when counting the number of Records in PROC FREQ or SQL?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the following example, I also look for my data to display the sex= 'Missing' record count as&amp;nbsp; '0'. In my way, I used to create a dummy record and then append it to my dataset. But I would like to learn the easy way if that's possible.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc FREQ with 'Sparse' option ,I was able to get the '0' for sex ='Female' and Age =16 . But I am&amp;nbsp; don't have the 'Missing' sex.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1678805207307.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81525iAAC9DA542CE352F5/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1678805207307.png" alt="SASuserlot_0-1678805207307.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;in SQL I don't get any of the missing counts.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_1-1678805307409.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81526iA83B7FCF02F2D4A6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_1-1678805307409.png" alt="SASuserlot_1-1678805307409.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
proc format;
      value $shf 'F'= 'Female'
                'M'= 'Male'
                'U' = 'Missing';
quit;

proc freq data = sashelp.class noprint;
	tables sex*age/ sparse out= cnt0 nocum norow nopercent;
	format sex $shf.;
quit;

proc sql;
     create table cnt1 as
     select sex format $shf.,age, count(*) as cnt from sashelp.class
         group by sex,age;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;LI-SPOILER&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Tue, 14 Mar 2023 14:51:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864076#M341260</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-03-14T14:51:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate 'PRELOADFMT' in FREQ , SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864102#M341272</link>
      <description>&lt;P&gt;Maybe use one of the procedures that uses preloadfmt to create an output data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you show what you actually expect for output? If you expect a missing for each for each age that can be done in Sql be creating an output set from the Proc Format code and joining that with the data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format out=work.shffmt;
      value $shf 'F'= 'Female'
                'M'= 'Male'
                'U' = 'Missing';
   select $shf;
quit;

proc sql;
     create table cnt1 as
     select b.start as sex format $shf.,age, count(*) as cnt 
     from sashelp.class as a
          ,work.shffmt as b
         group by b.start,age;
quit;&lt;/PRE&gt;
&lt;P&gt;But that gets very cumbersome if you want to do this for multiple variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 16:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864102#M341272</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-03-14T16:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate 'PRELOADFMT' in FREQ , SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864113#M341277</link>
      <description>&lt;P&gt;&amp;nbsp;Thank you,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;.&amp;nbsp; If with sql code works and is an easy solution, I am happy with that. Your code almost got what I wanted, but I have a question (request). There is no 'Female ' with age 16 in the ' class' data set ( selected observation in image)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_1-1678814936862.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81529i388479D5CDF5FCD9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_1-1678814936862.png" alt="SASuserlot_1-1678814936862.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is the output I am looking for (looking for highlighted one also to display in my final output along with other rows that have the count).&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1678814920719.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81528i7CFD59F3071DE46F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1678814920719.png" alt="SASuserlot_0-1678814920719.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 17:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864113#M341277</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-03-14T17:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate 'PRELOADFMT' in FREQ , SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864114#M341278</link>
      <description>&lt;P&gt;You don't want to count(*).&amp;nbsp; Instead you want to count(&lt;STRONG&gt;something&lt;/STRONG&gt;) where &lt;STRONG&gt;something&lt;/STRONG&gt; is a variable that will MISSING when the combination does not appear in the actual data and NOT missing when it does appear in the actual data.&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 17:35:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864114#M341278</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-14T17:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate 'PRELOADFMT' in FREQ , SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864119#M341279</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;. Unfortunately, I couldn't understand what you were saying. If I replace the "something" with any Variable, it gives me back the normal SQL counts with fewer records ( excluding those that are not in my data). However, I am looking for my final data to display like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;How I want:&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_0-1678815974390.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81531i6729BA4622CE17B7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_0-1678815974390.png" alt="SASuserlot_0-1678815974390.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;As per&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp; Suggesion: ( Sex ='Missing' is&amp;nbsp; shows up in cnt1, but there count also changed along with male and female counts)&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="SASuserlot_1-1678816292035.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/81533iBF1E3C0ED6DCA7AC/image-size/medium?v=v2&amp;amp;px=400" role="button" title="SASuserlot_1-1678816292035.png" alt="SASuserlot_1-1678816292035.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Mar 2023 17:52:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864119#M341279</guid>
      <dc:creator>SASuserlot</dc:creator>
      <dc:date>2023-03-14T17:52:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to simulate 'PRELOADFMT' in FREQ , SQL</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864125#M341281</link>
      <description>&lt;P&gt;The COUNT() function counts the non-missing values of the variable.&amp;nbsp; You cannot use SEX if you want to get the counts of the number of times the value of SEX is missing in the real data.&amp;nbsp; So you need some variable that is not missing on every observation in the actual dataset. If you don't have such a variable you will have make one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So if you created a template dataset with all of the combinations of SEX and AGE you want to report, left call it SHELL, then you could use code like this to join with SASHELP.CLASS and generate the counts.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data shell;
  do sex='M','F',' ';
    do age=10 to 16 ;
      output;
    end;
  end;
run;
proc sql noprint;
create table cnt1 as
  select
     b.sex
    ,b.age
    ,count(a.constant) as cnt 
  from (select sex,age, 1 as constant from sashelp.class) a
  full join shell b 
     on a.sex = b.sex and a.age = b.age
  group by 1,2
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results&lt;/P&gt;
&lt;PRE&gt;Obs    sex    age    cnt

  1            10     0
  2            11     0
  3            12     0
  4            13     0
  5            14     0
  6            15     0
  7            16     0
  8     F      10     0
  9     F      11     1
 10     F      12     2
 11     F      13     2
 12     F      14     2
 13     F      15     2
 14     F      16     0
 15     M      10     0
 16     M      11     1
 17     M      12     3
 18     M      13     1
 19     M      14     2
 20     M      15     2
 21     M      16     1

&lt;/PRE&gt;</description>
      <pubDate>Tue, 14 Mar 2023 18:06:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simulate-PRELOADFMT-in-FREQ-SQL/m-p/864125#M341281</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2023-03-14T18:06:28Z</dc:date>
    </item>
  </channel>
</rss>

