<?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: SAS : How to count number of records with a specific quality. in ODS and Base Reporting</title>
    <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5302#M2144</link>
    <description>David...I probably would have found the MIN and MAX ages in the data set and then used them for the start and stop values of the loop. That's because if you're going to use PRELOADFMT, then you want to only have it fill in the blanks from the MIN to the MAX age -- not from 1 to 100.&lt;BR /&gt;
&lt;BR /&gt;
Indeed, you are correct. I built the format based on the data that was presented in the question, because that was the quickest way to illustrate the different reporting techniques. I figured that if my top and bottom limit for format ages was problematic, that somebody would point it out. &lt;BR /&gt;
&lt;BR /&gt;
And now, we've had this lovely conversation about how to use reporting procedures to accomplish the task and learned more about PROC FORMAT besides! &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
    <pubDate>Mon, 05 Nov 2007 18:43:51 GMT</pubDate>
    <dc:creator>Cynthia_sas</dc:creator>
    <dc:date>2007-11-05T18:43:51Z</dc:date>
    <item>
      <title>SAS : How to count number of records with a specific quality.</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5298#M2140</link>
      <description>Hi, &lt;BR /&gt;
&lt;BR /&gt;
I am working on a requirement, which goes like this : &lt;BR /&gt;
&lt;BR /&gt;
Input File 1&lt;BR /&gt;
----------------&lt;BR /&gt;
name          sex   age&lt;BR /&gt;
*******          ***    ***&lt;BR /&gt;
ADAMS       M     20&lt;BR /&gt;
BAKER        F     19&lt;BR /&gt;
DOUGLAS   M     19&lt;BR /&gt;
HALE          M     21&lt;BR /&gt;
JONE          F     19&lt;BR /&gt;
LARUE        F     18&lt;BR /&gt;
NICK           M     19&lt;BR /&gt;
OLA            M     22&lt;BR /&gt;
PEBBLE      F  22&lt;BR /&gt;
RAINES       F  21&lt;BR /&gt;
&lt;BR /&gt;
Input File 2&lt;BR /&gt;
----------------&lt;BR /&gt;
AGE   DESCRIPTION&lt;BR /&gt;
*****    ******************&lt;BR /&gt;
19       nineteen years old     &lt;BR /&gt;
20        twenty years old       &lt;BR /&gt;
21        twenty one years old   &lt;BR /&gt;
22        twenty two years old   &lt;BR /&gt;
23         twenty three years old &lt;BR /&gt;
24        twenty four years old  &lt;BR /&gt;
25        twenty five years old  &lt;BR /&gt;
&lt;BR /&gt;
I sort both the files on AGE, and I want the o.p to be  &lt;BR /&gt;
&lt;BR /&gt;
AGE   TOTAL NUMBER OF PEOPLE IN THAT AGE    DESCRIPTION&lt;BR /&gt;
19           2                                                                 nineteen years old&lt;BR /&gt;
&lt;BR /&gt;
I want to know how I do this. &lt;BR /&gt;
&lt;BR /&gt;
My logic is to &lt;BR /&gt;
&lt;BR /&gt;
1. read the first record in SAS. Have the count variable set as 0.&lt;BR /&gt;
2. store the AGE in a temp variable. And have count variable set as 1.&lt;BR /&gt;
3. Read the next record, and get the AGE. &lt;BR /&gt;
4. Compare the temp value and the AGE. &lt;BR /&gt;
     If both are same : count + 1&lt;BR /&gt;
     If the age &amp;gt; temp, then &lt;BR /&gt;
                                     write a record into the o.p file - &lt;AGE&gt; &lt;COUNT&gt;&lt;BR /&gt;
&lt;BR /&gt;
&lt;BR /&gt;
Do the same until end of file. &lt;BR /&gt;
&lt;BR /&gt;
I am quite new to SAS, so I am not able to find out how I can accomplish this in SAS. Any help or any guidance in this regard would be very helpful.... &lt;BR /&gt;
&lt;BR /&gt;
Thanks. &lt;BR /&gt;
Murali.&lt;/COUNT&gt;&lt;/AGE&gt;</description>
      <pubDate>Thu, 01 Nov 2007 07:20:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5298#M2140</guid>
      <dc:creator>m_u_r_a_l_i</dc:creator>
      <dc:date>2007-11-01T07:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: SAS : How to count number of records with a specific quality.</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5299#M2141</link>
      <description>Hi:&lt;BR /&gt;
  If this were my task, I would not start by counting the records myself until after I'd figured out whether any of the reporting procedures could suit my needs. For example, PROC FREQ, PROC REPORT, PROC TABULATE, PROC SQL, all have ways to count and categorize records in the manner you want. If you review the results from the following program, you will see that each technique produces a slightly different result, and, depending on what you want, one of these may be a quicker approach than writing your own program to perform this task.&lt;BR /&gt;
 &lt;BR /&gt;
  If you need help with any of the syntax used in these programs, you might consider looking at the documentation for each procedure for more help. Or, Tech Support can help you with the details of whatever method you finally select.&lt;BR /&gt;
 &lt;BR /&gt;
 cynthia&lt;BR /&gt;
[pre]&lt;BR /&gt;
** make some data to test;&lt;BR /&gt;
data file1;&lt;BR /&gt;
  infile datalines;&lt;BR /&gt;
  input Name $ Gender $ Age;&lt;BR /&gt;
return;&lt;BR /&gt;
datalines;&lt;BR /&gt;
ADAMS M 20&lt;BR /&gt;
BAKER F 19&lt;BR /&gt;
DOUGLAS M 19&lt;BR /&gt;
HALE M 21&lt;BR /&gt;
JONE F 19&lt;BR /&gt;
LARUE F 18&lt;BR /&gt;
NICK M 19&lt;BR /&gt;
OLA M 22&lt;BR /&gt;
PEBBLE F 22&lt;BR /&gt;
RAINES F 21&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
   &lt;BR /&gt;
** make a user-defined format for the age description;&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value agef &lt;BR /&gt;
      18 = 'Eighteen years old'&lt;BR /&gt;
      19 = 'Nineteen years old' &lt;BR /&gt;
      20 = 'Twenty years old '&lt;BR /&gt;
      21 = 'Twenty one years old' &lt;BR /&gt;
      22 = 'Twenty two years old' &lt;BR /&gt;
      23 = 'Twenty three years old' &lt;BR /&gt;
      24 = 'Twenty four years old' &lt;BR /&gt;
      25 = 'Twenty five years old ';&lt;BR /&gt;
run;&lt;BR /&gt;
    &lt;BR /&gt;
** start ODS;&lt;BR /&gt;
ods html file='c:\temp\useReport.html' style=egdefault;&lt;BR /&gt;
   &lt;BR /&gt;
** PROC FREQ;&lt;BR /&gt;
proc freq data=file1;&lt;BR /&gt;
  title '1) Using PROC FREQ';&lt;BR /&gt;
  tables Age;&lt;BR /&gt;
  format Age agef.;&lt;BR /&gt;
  label Age = 'Age Description';&lt;BR /&gt;
run;&lt;BR /&gt;
       &lt;BR /&gt;
** PROC SQL;&lt;BR /&gt;
title "2) Using PROC SQL";&lt;BR /&gt;
proc sql;&lt;BR /&gt;
  select age label='Age', &lt;BR /&gt;
         count(age) as cntage label='Total People',&lt;BR /&gt;
         put(age,agef.) as desc label='Description'&lt;BR /&gt;
  from work.file1&lt;BR /&gt;
  group by age&lt;BR /&gt;
  order by age;&lt;BR /&gt;
quit;&lt;BR /&gt;
        &lt;BR /&gt;
** PROC REPORT;&lt;BR /&gt;
proc report data=file1 nowd;&lt;BR /&gt;
  title '3) Using PROC REPORT';&lt;BR /&gt;
  column age agegrp n age=desc;&lt;BR /&gt;
  define age /group noprint;&lt;BR /&gt;
  define agegrp/ computed 'Age' ;&lt;BR /&gt;
  define n / 'Total Number of People';&lt;BR /&gt;
  define desc / group f=agef. 'In this Age Description' ;&lt;BR /&gt;
  rbreak after / summarize;&lt;BR /&gt;
  compute agegrp / character length=5;&lt;BR /&gt;
    agegrp = right(put(age,5.));&lt;BR /&gt;
    if _break_ = '_RBREAK_' then do;&lt;BR /&gt;
       agegrp = 'Total';&lt;BR /&gt;
    end;&lt;BR /&gt;
  endcomp;&lt;BR /&gt;
run;&lt;BR /&gt;
       &lt;BR /&gt;
** PROC TABULATE;&lt;BR /&gt;
options missing=0;&lt;BR /&gt;
proc tabulate data=file1 f=comma8.;&lt;BR /&gt;
  title "4) Using PROC TABULATE";&lt;BR /&gt;
  class age /preloadfmt;&lt;BR /&gt;
  table age all, n / printmiss;&lt;BR /&gt;
  label age = 'Age Description';&lt;BR /&gt;
  keylabel n = 'Total All People In This Category'&lt;BR /&gt;
          all = 'Grand Total';&lt;BR /&gt;
  format age agef.;&lt;BR /&gt;
run;&lt;BR /&gt;
  &lt;BR /&gt;
options missing = .;&lt;BR /&gt;
title;&lt;BR /&gt;
ods html close;&lt;BR /&gt;
[/pre]</description>
      <pubDate>Thu, 01 Nov 2007 19:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5299#M2141</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-11-01T19:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: SAS : How to count number of records with a specific quality.</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5300#M2142</link>
      <description>Hi, &lt;BR /&gt;
&lt;BR /&gt;
Thanks for the response. After reading through your code, especially &lt;BR /&gt;
** make a user-defined format for the age description; section, I wish to tell you that there is another challenge in this requirement. &lt;BR /&gt;
&lt;BR /&gt;
I have given the age as 19 to 25. But in the real time scneario, I might have N number of ages, and i dont know how many would be there. So how would I be able to define.</description>
      <pubDate>Mon, 05 Nov 2007 06:51:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5300#M2142</guid>
      <dc:creator>m_u_r_a_l_i</dc:creator>
      <dc:date>2007-11-05T06:51:58Z</dc:date>
    </item>
    <item>
      <title>Re: SAS : How to count number of records with a specific quality.</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5301#M2143</link>
      <description>I read Cynthia's response, amazed at how well she had covered the requirements, without straying too far from the goals.  I did wonder though at the format, thinking it was a little constrained by an understanding of the data.  Experience tells me that understanding of the data more often starts when SAS is applied to it, and everyone learns something new.&lt;BR /&gt;
&lt;BR /&gt;
In this case, I thought the format could be created from a table of values, and it would not have the risks of miscoding, or missing values.  The following code will create a format from 1 to 100 and can be extended easily as far as is needed.&lt;BR /&gt;
&lt;BR /&gt;
[Pre]&lt;BR /&gt;
Data CNTLIN;&lt;BR /&gt;
  Retain FMTNAME "AGEF"&lt;BR /&gt;
         TYPE    "N";&lt;BR /&gt;
  Length LABEL $60;&lt;BR /&gt;
  Do START = 1  To  100  By  1;&lt;BR /&gt;
    LABEL = CompBl( Put( START, WORDS30.) || "years old");&lt;BR /&gt;
    Output;&lt;BR /&gt;
  End;&lt;BR /&gt;
Run;&lt;BR /&gt;
&lt;BR /&gt;
Proc Format CntlIn = CNTLIN;&lt;BR /&gt;
Run;&lt;BR /&gt;
[/Pre]&lt;BR /&gt;
&lt;BR /&gt;
Kind regards&lt;BR /&gt;
&lt;BR /&gt;
David</description>
      <pubDate>Mon, 05 Nov 2007 08:25:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5301#M2143</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-05T08:25:26Z</dc:date>
    </item>
    <item>
      <title>Re: SAS : How to count number of records with a specific quality.</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5302#M2144</link>
      <description>David...I probably would have found the MIN and MAX ages in the data set and then used them for the start and stop values of the loop. That's because if you're going to use PRELOADFMT, then you want to only have it fill in the blanks from the MIN to the MAX age -- not from 1 to 100.&lt;BR /&gt;
&lt;BR /&gt;
Indeed, you are correct. I built the format based on the data that was presented in the question, because that was the quickest way to illustrate the different reporting techniques. I figured that if my top and bottom limit for format ages was problematic, that somebody would point it out. &lt;BR /&gt;
&lt;BR /&gt;
And now, we've had this lovely conversation about how to use reporting procedures to accomplish the task and learned more about PROC FORMAT besides! &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;BR /&gt;
 &lt;BR /&gt;
cynthia</description>
      <pubDate>Mon, 05 Nov 2007 18:43:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5302#M2144</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2007-11-05T18:43:51Z</dc:date>
    </item>
    <item>
      <title>Re: SAS : How to count number of records with a specific quality.</title>
      <link>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5303#M2145</link>
      <description>I confess, my answer was only an A- because I didn't take account of the data, and sought a generic solution.  Even though I had also commented that data understanding was important.  So, we have the A+ answer to find the boundaries and deliver a format that would be conservative.&lt;BR /&gt;
&lt;BR /&gt;
I didn't even consider the preloadfmt implications Cynthia, thank you for sharing them.&lt;BR /&gt;
&lt;BR /&gt;
Kind regards&lt;BR /&gt;
&lt;BR /&gt;
David</description>
      <pubDate>Tue, 06 Nov 2007 02:11:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/ODS-and-Base-Reporting/SAS-How-to-count-number-of-records-with-a-specific-quality/m-p/5303#M2145</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2007-11-06T02:11:06Z</dc:date>
    </item>
  </channel>
</rss>

