<?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: Apply format with many values to keep zero counts in proc freq in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Apply-format-with-many-values-to-keep-zero-counts-in-proc-freq/m-p/593664#M170407</link>
    <description>&lt;P&gt;One way is to write your format in a data step and read it into PROC FORMAT like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fmt;
    retain fmtname "digits";
    do start=100 to 999;
        label=put(start, 3.);
        output;
    end;
run;

proc format library=work cntlin=fmt;
run;

data test2;
 input person $1. first_3digit;
 datalines;
A 101
A 253
A 336
A 101
B 245
B 245
B 405
B 504
C 101
C 666
C 789
;

proc summary data=test2 nway completetypes;
 class first_3digit / preloadfmt order=data missing;
 FORMAT first_3digit digits.;
 output out=first_digit_counts;
run;

PROC FREQ DATA=first_digit_counts order=data NOPRINT;
 TABLES first_3digit / MISSING OUT=distribution 
  (RENAME=(PERCENT=OBSERVED));
 weight _freq_ / zeros;
 FORMAT first_3digit digits.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Oct 2019 11:00:48 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-10-03T11:00:48Z</dc:date>
    <item>
      <title>Apply format with many values to keep zero counts in proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apply-format-with-many-values-to-keep-zero-counts-in-proc-freq/m-p/593656#M170402</link>
      <description>&lt;P&gt;I have a working script, see below, to keep zero counts in a proc freq for one variable. This is based on the solution of a&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Procedures/PROC-FREQ-Include-Zero-Counts/td-p/325505" target="_self"&gt;former question&lt;/A&gt;&amp;nbsp;on this forum.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	input person $1. first_digit;
	datalines;
A 1
A 2
A 3
A 1
B 2
B 3
B 4
B 5
C 1
C 6
C 7
;
run;

/* Make sure zero counts are kept*/
proc format;
	value digits
		1='1'
		2='2'
		3='3'
		4='4'
		5='5'
		6='6'
		7='7'
		8='8'
		9='9';
quit;

proc summary data=test nway completetypes;
	class first_digit / preloadfmt order=data missing;
	FORMAT	first_digit	digits.;
	output out=first_digit_counts;
	by person;
run;

PROC	FREQ	DATA=first_digit_counts order=data NOPRINT;
	by person;
	TABLES	first_digit	/	MISSING OUT=distribution 
		(RENAME=(PERCENT=OBSERVED));
	weight _freq_ / zeros;
	FORMAT	first_digit	digits.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Now I need to apply the same script, but the possible values are now 100 to 999 instead of 1 to 9. I want to avoid having to type out all numbers in the proc format step (it can be easily done with the help of excel, but it clutters my code). &lt;STRONG&gt;I already have a table at my disposition that has all possible values&lt;/STRONG&gt; for first_3digit (100-999) as a numeric variable. Is there a way I can do the proc format step more efficiently?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Some sample data on which it should work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test2;
	input person $1. first_3digit;
	datalines;
A 101
A 253
A 336
A 101
B 245
B 245
B 405
B 504
C 101
C 666
C 789
;
run&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 09:36:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apply-format-with-many-values-to-keep-zero-counts-in-proc-freq/m-p/593656#M170402</guid>
      <dc:creator>SarahDew</dc:creator>
      <dc:date>2019-10-03T09:36:29Z</dc:date>
    </item>
    <item>
      <title>Re: Apply format with many values to keep zero counts in proc freq</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Apply-format-with-many-values-to-keep-zero-counts-in-proc-freq/m-p/593664#M170407</link>
      <description>&lt;P&gt;One way is to write your format in a data step and read it into PROC FORMAT like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data fmt;
    retain fmtname "digits";
    do start=100 to 999;
        label=put(start, 3.);
        output;
    end;
run;

proc format library=work cntlin=fmt;
run;

data test2;
 input person $1. first_3digit;
 datalines;
A 101
A 253
A 336
A 101
B 245
B 245
B 405
B 504
C 101
C 666
C 789
;

proc summary data=test2 nway completetypes;
 class first_3digit / preloadfmt order=data missing;
 FORMAT first_3digit digits.;
 output out=first_digit_counts;
run;

PROC FREQ DATA=first_digit_counts order=data NOPRINT;
 TABLES first_3digit / MISSING OUT=distribution 
  (RENAME=(PERCENT=OBSERVED));
 weight _freq_ / zeros;
 FORMAT first_3digit digits.;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Oct 2019 11:00:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Apply-format-with-many-values-to-keep-zero-counts-in-proc-freq/m-p/593664#M170407</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-03T11:00:48Z</dc:date>
    </item>
  </channel>
</rss>

