<?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: Aggregate to individual level data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/955919#M373298</link>
    <description>&lt;P&gt;Well, I can't say I know why you'd do such a thing, but you could do it like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input clinic $ Agegrp$ TotalPatient TotalFemale FemaleMedReceived TotalMale MaleMedReceived;
datalines;
ABC 1-5 104 56 2 48 0
ABC 6-10 232 111 16 121 13
ABC 11-15 192 108 4 84 3;
run;

data want;
set have;
MedReceived='Y';
Sex='F';
do i=1 to TotalFemale;
    if i&amp;gt;FemaleMedReceived then MedReceived='N';
    output;
end;
MedReceived='Y';
Sex='M';
do i=1 to TotalMale;
    if i&amp;gt;MaleMedReceived then MedReceived='N';
    output;
end;
keep clinic ageGrp Sex MedReceived;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 13 Jan 2025 14:56:56 GMT</pubDate>
    <dc:creator>quickbluefish</dc:creator>
    <dc:date>2025-01-13T14:56:56Z</dc:date>
    <item>
      <title>Aggregate to individual level data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/955913#M373296</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to convert the aggregate-level data into individual-level data. I would really appreciate the help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data temp;&lt;/P&gt;
&lt;P&gt;input clinic $ Agegrp$ TotalPatient TotalFemale FemaleMedReceived TotalMale MaleMedReceived;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;ABC 1-5 104 56 2 48 0&lt;/P&gt;
&lt;P&gt;ABC 6-10 232 111 16 121 13&lt;/P&gt;
&lt;P&gt;ABC 11-15 192 108 4 84 3;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Table I have:&lt;/P&gt;
&lt;TABLE border="1" width="100.00000000000001%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%" height="85px"&gt;Clinic&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="85px"&gt;Age Group&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="85px"&gt;Total Patients&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="85px"&gt;Total Female&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="85px"&gt;Female Medication received&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="85px"&gt;Total Male&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="85px"&gt;Male Medication received&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;ABC&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;1-5&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;104&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;56&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;48&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;6-10&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;232&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;111&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;16&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;121&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;13&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;11-15&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;192&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;108&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;84&lt;/TD&gt;
&lt;TD width="14.285714285714286%" height="30px"&gt;3&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create individual-level data from the above numbers. For example, the table I want should have each row with clinic and age group (1-5), with 56 females - 2 of those should receive Medication (Yes), and 54 should not receive medication (No). The same is true for males 1-5 years old (48 males—0, medication (Yes) and 48 medication (No)).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The table I want has a total of 528 rows:&lt;/P&gt;
&lt;TABLE border="1" width="100%"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;Clinic&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;Age Group&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;Gender&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;Medication Received&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;ABC&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;1-5&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;F&amp;nbsp;&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;Yes&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;ABC&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;1-5&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;F&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;Yes&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;.......&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;....&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;....&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;....&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;ABC&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;1-5&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;M&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;No&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;ABC&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;1-5&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;M&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;No&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;......&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;....&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;....&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;....&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="25%" height="30px"&gt;ABC&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;5-10&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;F&lt;/TD&gt;
&lt;TD width="25%" height="30px"&gt;Yes&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/188593"&gt;@sandyzman1&lt;/a&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2025 14:34:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/955913#M373296</guid>
      <dc:creator>sandyzman1</dc:creator>
      <dc:date>2025-01-13T14:34:48Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate to individual level data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/955916#M373297</link>
      <description>&lt;P&gt;So do you want to generate one record per "person" base on the values of&amp;nbsp;&lt;SPAN&gt;TotalFemale and TotalMale columns?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I would probably use two nested do-loops (one for each gender and with/without MedReceived). In each loop an explicit OUTPUT statment.&lt;/SPAN&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do f = 1 to TotalFemale;
   do fr = 1 to FemaleMedReceived;
      MedReceived = 'Yes';
      Output;
   end;
   do fnr = 1 to TotalFemale - FemaleMedReceived;
      MedReceived = 'No';
      Output;
   end;
end;
/* repeat same logic for male below */&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jan 2025 14:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/955916#M373297</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2025-01-13T14:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate to individual level data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/955919#M373298</link>
      <description>&lt;P&gt;Well, I can't say I know why you'd do such a thing, but you could do it like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
input clinic $ Agegrp$ TotalPatient TotalFemale FemaleMedReceived TotalMale MaleMedReceived;
datalines;
ABC 1-5 104 56 2 48 0
ABC 6-10 232 111 16 121 13
ABC 11-15 192 108 4 84 3;
run;

data want;
set have;
MedReceived='Y';
Sex='F';
do i=1 to TotalFemale;
    if i&amp;gt;FemaleMedReceived then MedReceived='N';
    output;
end;
MedReceived='Y';
Sex='M';
do i=1 to TotalMale;
    if i&amp;gt;MaleMedReceived then MedReceived='N';
    output;
end;
keep clinic ageGrp Sex MedReceived;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Jan 2025 14:56:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/955919#M373298</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-13T14:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate to individual level data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/955951#M373306</link>
      <description>&lt;P&gt;Are there &lt;STRONG&gt;any other variables&lt;/STRONG&gt;?&lt;/P&gt;
&lt;P&gt;I ask because the data set you create has the possibility of implying precision for other variables, or your variables combined with the one shown, that would very likely be false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would be interested in what the resulting data set is to be used for. I may be that you think you need to dis-aggregate the values you have when use of other options may allow use of the existing data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For what little it may be worth you may want to consider using numeric 1&amp;nbsp; and 0 values instead of text "yes" and "no". The sum of a 1/0 coded variable is the number of '1' values, the mean is a decimal percentage and some other tricks involving "any" "all" or "none" of the 1 and 0 values can be done with the functions max, min, and range that involve moderately ugly programming with character 'yes' and 'no'.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2025 18:25:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/955951#M373306</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-01-13T18:25:25Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate to individual level data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/956313#M373449</link>
      <description>Thanks !</description>
      <pubDate>Thu, 16 Jan 2025 15:07:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/956313#M373449</guid>
      <dc:creator>sandyzman1</dc:creator>
      <dc:date>2025-01-16T15:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate to individual level data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/956314#M373450</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; Thanks for the reply. I get what you are trying to point out. I do have other variables. This is just a snippet of the dataset. However, I created a separate dataset using the above-suggested code and merged it by Patient ID. It seems to work fine. Also, I think considering using numeric values is a great choice. I did use it as a numeric instead of text. I planned to use the variables for the mixed model logistic regression. Thanks.</description>
      <pubDate>Thu, 16 Jan 2025 15:11:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-to-individual-level-data/m-p/956314#M373450</guid>
      <dc:creator>sandyzman1</dc:creator>
      <dc:date>2025-01-16T15:11:59Z</dc:date>
    </item>
  </channel>
</rss>

