<?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 can I collapse data using sas? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278674#M58932</link>
    <description>&lt;P&gt;Note that once you do this, you may lose some data.&amp;nbsp; It would be possible, for example, that HAIR would be different on different original observations.&amp;nbsp; But you will end up with only one value after the collapse.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That being said, here's a way to approach this.&amp;nbsp; Assuming you have a variable named ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;update have (obs=0) have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output data set should be just what you are looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
    <pubDate>Mon, 20 Jun 2016 13:43:34 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-06-20T13:43:34Z</dc:date>
    <item>
      <title>How can I collapse data using sas?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278668#M58930</link>
      <description>&lt;P&gt;Hi everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am new to SAS and just learning from scratch.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need help understanding how to collapse my data. I have a data set with a number of observations with a unique ID number. However, these observations may be entered more than once in the dataset becuase they have a variable of interest. So for example, observation #1234 might be listed 5 times in the data set because they have the colour blue, short hair, height x, black hair and eat meat. What I want to do is collapse my data so that I only have one observation for #1234 but be able to see all the variables that they have in one line instead of 5 separate entries.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How can I do this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 13:30:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278668#M58930</guid>
      <dc:creator>christinagting0</dc:creator>
      <dc:date>2016-06-20T13:30:52Z</dc:date>
    </item>
    <item>
      <title>Re: How can I collapse data using sas?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278672#M58931</link>
      <description>&lt;P&gt;Look at proc transpose. It is the tool for exactly this kind of operation.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 13:38:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278672#M58931</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-06-20T13:38:46Z</dc:date>
    </item>
    <item>
      <title>Re: How can I collapse data using sas?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278674#M58932</link>
      <description>&lt;P&gt;Note that once you do this, you may lose some data.&amp;nbsp; It would be possible, for example, that HAIR would be different on different original observations.&amp;nbsp; But you will end up with only one value after the collapse.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That being said, here's a way to approach this.&amp;nbsp; Assuming you have a variable named ID:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sort data=have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;update have (obs=0) have;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The output data set should be just what you are looking for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 13:43:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278674#M58932</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-20T13:43:34Z</dc:date>
    </item>
    <item>
      <title>Re: How can I collapse data using sas?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278678#M58933</link>
      <description>&lt;P&gt;Hi Astounding,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;thanks for your reply. Do you think you could explain your code a bit further so I can understand what is happening?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understand the proc sort, but I"m a little confused as to what the obs=0 line is saying. When I googled it it says that obs=0&amp;nbsp;&lt;SPAN&gt;creates an empty data set that has the structure, but not the attributes, of another data set.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;i'm a little confused how your code collapses data?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thank you!!!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 13:53:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278678#M58933</guid>
      <dc:creator>christinagting0</dc:creator>
      <dc:date>2016-06-20T13:53:26Z</dc:date>
    </item>
    <item>
      <title>Re: How can I collapse data using sas?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278694#M58939</link>
      <description>&lt;P&gt;When creating an output data set, OBS=0 creates an empty data set.&amp;nbsp; But when reading an incoming data set, OBS=0 reads zero observations from the data set.&amp;nbsp; That's important here, because the UPDATE statement requires two datasets:&amp;nbsp; a master data set, and a set of transactions to apply to that master data set.&amp;nbsp; In effect, the UPDATE statement in this program is saying that the master data set contains zero observations, and all the data is coming from the transaction data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;UPDATE is not necessarily where you would start learning about SAS.&amp;nbsp; It just happens to be a good tool for this particular job.&amp;nbsp; It automatically ignores missing values, and automatically outputs one observation for each value of the BY variable (after all the transactions have been applied).&lt;/P&gt;</description>
      <pubDate>Mon, 20 Jun 2016 14:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/How-can-I-collapse-data-using-sas/m-p/278694#M58939</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-20T14:27:28Z</dc:date>
    </item>
  </channel>
</rss>

