<?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: Condense multiple observations into one retaining all variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Condense-multiple-observations-into-one-retaining-all-variables/m-p/932242#M366724</link>
    <description>&lt;P&gt;Something like this should work:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table UniqueId as
   select distinct Id 
   from yourdatasetname
   ;
quit;

proc sort data=yourdatasetname;
   by id;
run;

data want;
   update uniqueid yourdatasetname;
   by id;
run;&lt;/PRE&gt;
&lt;P&gt;Note that if the "grades" were numeric values this could be done with proc summary in one step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is best to provide data in the form of a working data step. If I have to make a data set from another format I may may things that don't actually match your variable types and may not have the same variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Jun 2024 17:36:23 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2024-06-13T17:36:23Z</dc:date>
    <item>
      <title>Condense multiple observations into one retaining all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Condense-multiple-observations-into-one-retaining-all-variables/m-p/932240#M366723</link>
      <description>&lt;P&gt;My data comprises multiple IDs and grades for those IDs in multiple terms. I want to condense the dataset so that each unique ID has only one line while all of the columns retain the full grade information.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It currently looks like this:&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 384pt;" border="0" width="512" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" style="height: 12.75pt; width: 48pt;"&gt;&lt;FONT size="2"&gt;ID&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px" style="width: 48pt;"&gt;&lt;FONT size="2"&gt;SP20&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px" style="width: 48pt;"&gt;&lt;FONT size="2"&gt;SM20&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px" style="width: 48pt;"&gt;&lt;FONT size="2"&gt;FA20&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px" style="width: 48pt;"&gt;&lt;FONT size="2"&gt;SP21&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px" style="width: 48pt;"&gt;&lt;FONT size="2"&gt;SM21&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px" style="width: 48pt;"&gt;&lt;FONT size="2"&gt;FA21&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px" style="width: 48pt;"&gt;&lt;FONT size="2"&gt;SP22&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" align="right" style="height: 12.75pt;"&gt;&lt;FONT size="2"&gt;1001&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px"&gt;&lt;FONT size="2"&gt;A+&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" align="right" style="height: 12.75pt;"&gt;&lt;FONT size="2"&gt;1002&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&lt;FONT size="2"&gt;D&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" align="right" style="height: 12.75pt;"&gt;&lt;FONT size="2"&gt;1002&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&lt;FONT size="2"&gt;F&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" align="right" style="height: 12.75pt;"&gt;&lt;FONT size="2"&gt;1003&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&lt;FONT size="2"&gt;B&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" align="right" style="height: 12.75pt;"&gt;&lt;FONT size="2"&gt;1004&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&lt;FONT size="2"&gt;A+&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" align="right" style="height: 12.75pt;"&gt;&lt;FONT size="2"&gt;1005&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&lt;FONT size="2"&gt;B-&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" align="right" style="height: 12.75pt;"&gt;&lt;FONT size="2"&gt;1006&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&lt;FONT size="2"&gt;A+&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" align="right" style="height: 12.75pt;"&gt;&lt;FONT size="2"&gt;1007&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&lt;FONT size="2"&gt;F&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="63.8594px" height="12px" align="right" style="height: 12.75pt;"&gt;&lt;FONT size="2"&gt;1007&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9062px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.875px" height="12px"&gt;&lt;FONT size="2"&gt;B+&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD width="63.8438px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="63.9219px" height="12px"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that IDs 1002 and 1007 each have two lines because they took the course twice, i.e., in two different semesters.&lt;/P&gt;
&lt;P&gt;I want it to become this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE style="border-collapse: collapse; width: 384pt;" border="0" width="512" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD width="64" height="17" style="height: 12.75pt; width: 48pt;"&gt;ID&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;SP20&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;SM20&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;FA20&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;SP21&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;SM21&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;FA21&lt;/TD&gt;
&lt;TD width="64" style="width: 48pt;"&gt;SP22&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="height: 12.75pt;"&gt;1001&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;A+&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="height: 12.75pt;"&gt;1002&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;D&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;F&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="height: 12.75pt;"&gt;1003&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;B&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="height: 12.75pt;"&gt;1004&lt;/TD&gt;
&lt;TD&gt;A+&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="height: 12.75pt;"&gt;1005&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;B-&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="height: 12.75pt;"&gt;1006&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;A+&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR style="height: 12.75pt;"&gt;
&lt;TD height="17" align="right" style="height: 12.75pt;"&gt;1007&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;F&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;B+&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that IDs 1002 and 1007 are now on only one line while the grades from each semester are now included.&lt;/P&gt;
&lt;P&gt;Attached is a csv of the same data above.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 17:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Condense-multiple-observations-into-one-retaining-all-variables/m-p/932240#M366723</guid>
      <dc:creator>ericdrosano</dc:creator>
      <dc:date>2024-06-13T17:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Condense multiple observations into one retaining all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Condense-multiple-observations-into-one-retaining-all-variables/m-p/932242#M366724</link>
      <description>&lt;P&gt;Something like this should work:&lt;/P&gt;
&lt;PRE&gt;proc sql;
   create table UniqueId as
   select distinct Id 
   from yourdatasetname
   ;
quit;

proc sort data=yourdatasetname;
   by id;
run;

data want;
   update uniqueid yourdatasetname;
   by id;
run;&lt;/PRE&gt;
&lt;P&gt;Note that if the "grades" were numeric values this could be done with proc summary in one step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is best to provide data in the form of a working data step. If I have to make a data set from another format I may may things that don't actually match your variable types and may not have the same variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 17:36:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Condense-multiple-observations-into-one-retaining-all-variables/m-p/932242#M366724</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2024-06-13T17:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: Condense multiple observations into one retaining all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Condense-multiple-observations-into-one-retaining-all-variables/m-p/932245#M366725</link>
      <description>Will send proper format of data next time.&lt;BR /&gt;I wish I could use numeric values, but it's more complicated than just A-F scale, including QN, INC, NC, P,  and many more "grades".</description>
      <pubDate>Thu, 13 Jun 2024 17:42:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Condense-multiple-observations-into-one-retaining-all-variables/m-p/932245#M366725</guid>
      <dc:creator>ericdrosano</dc:creator>
      <dc:date>2024-06-13T17:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: Condense multiple observations into one retaining all variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Condense-multiple-observations-into-one-retaining-all-variables/m-p/932255#M366728</link>
      <description>&lt;P&gt;You don't need the separate dataset.&amp;nbsp; Just use the one dataset for both of the inputs that the UPDATE statement needs.&amp;nbsp; Use the OBS=0 dataset option to start with 0 observations in the original dataset and treat all of the observations as transactions to it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=yourdatasetname;
   by id;
run;

data want;
   update yourdatasetname(obs=0) yourdatasetname;
   by id;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2024 19:01:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Condense-multiple-observations-into-one-retaining-all-variables/m-p/932255#M366728</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-06-13T19:01:46Z</dc:date>
    </item>
  </channel>
</rss>

