<?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 SAS Retain in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754813#M238115</link>
    <description>&lt;P&gt;Input&amp;nbsp; ID&amp;nbsp; Zip;&lt;BR /&gt;101&amp;nbsp; &amp;nbsp;400201&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp;400333&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp;650067&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp;560103&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp;560067&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;How to get output.&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp;400201,400333&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp;650067&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp;560103,560067&lt;/P&gt;</description>
    <pubDate>Sun, 18 Jul 2021 03:29:21 GMT</pubDate>
    <dc:creator>Brijesh4sas</dc:creator>
    <dc:date>2021-07-18T03:29:21Z</dc:date>
    <item>
      <title>SAS Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754813#M238115</link>
      <description>&lt;P&gt;Input&amp;nbsp; ID&amp;nbsp; Zip;&lt;BR /&gt;101&amp;nbsp; &amp;nbsp;400201&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp;400333&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp;650067&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp;560103&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp;560067&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;How to get output.&lt;/P&gt;&lt;P&gt;101&amp;nbsp; &amp;nbsp;400201,400333&lt;/P&gt;&lt;P&gt;102&amp;nbsp; &amp;nbsp;650067&lt;/P&gt;&lt;P&gt;103&amp;nbsp; &amp;nbsp;560103,560067&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jul 2021 03:29:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754813#M238115</guid>
      <dc:creator>Brijesh4sas</dc:creator>
      <dc:date>2021-07-18T03:29:21Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754815#M238116</link>
      <description>&lt;P&gt;How many codes do you expect to place in a single variable? You should specify a length for the variable long enough to hold that many values plus the comma separator.&lt;/P&gt;
&lt;P&gt;Are there &lt;STRONG&gt;any&lt;/STRONG&gt; other variables to be involved in this? If so, what happens with them?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This question gets asked in one form another at least once per week.&lt;/P&gt;
&lt;P&gt;If the data is sorted by the ID variable then something like:&lt;/P&gt;
&lt;PRE&gt;data want; 
   set have;
   by id;&lt;BR /&gt;   length codelist $ 200.;
   retain codelist;
   if first.id then call missing (codelist);
   codelist = catx(',',codelist,zip);
  i last.id then output;
  keep id codelist;
run;&lt;/PRE&gt;
&lt;P&gt;If the data is not sorted by ID then do so.&lt;/P&gt;
&lt;P&gt;This sets the length of the combined variable to 200 characters which will hold about 28 codes. Adjust the length on the length statement to match actual need.&lt;/P&gt;
&lt;P&gt;When you use BY group processing SAS creates automatic variables that indicate whether a particular observation is the first or last of a particular by variable grouping and is a 1/0 (true/false) value accessed by using first.variablename and last.variable name.&lt;/P&gt;
&lt;P&gt;The code above clears the existing codelist variable when the first observation of the Id is encountered, then adds the zip to the list.&lt;/P&gt;
&lt;P&gt;The values are written out to the data set only when the last observation for an id value is encountered.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And just what do you expect to do with that resulting data set that can't be done with the one you have now? Anything that uses that codelist variable is going to be hard to actually work with for counting, modeling, just about any analysis or graphing?&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jul 2021 04:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754815#M238116</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-07-18T04:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754831#M238119</link>
      <description>&lt;P&gt;I feel compelled to repeat advice already given.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't re-arrange your data like this. Your programming would be much easier if you did not re-arrange data like this. To quote &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And just what do you expect to do with that resulting data set that can't be done with the one you have now? Anything that uses that codelist variable is going to be hard to actually work with for counting, modeling, just about any analysis or graphing?&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jul 2021 10:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754831#M238119</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-18T10:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754852#M238139</link>
      <description>&lt;P&gt;So, what would be a better way to structure data like this for for counting, modeling, just about any analysis or graphing?&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jul 2021 14:35:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754852#M238139</guid>
      <dc:creator>urban58</dc:creator>
      <dc:date>2021-07-18T14:35:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS Retain</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754858#M238145</link>
      <description>&lt;P&gt;The better way is to keep the data set as it was originally presented. In other words, one observation for each value of ID and ZIP. Not two (or more) zips on one line.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: All of this depends on what the next step is, what analysis or report or chart is going to be created. Certainly, there could be very rare and unusual cases where you want two (or more) zips on one line, but even then I would be skeptical that this is really needed (as it said, it would be very rare)&lt;/P&gt;</description>
      <pubDate>Sun, 18 Jul 2021 15:17:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-Retain/m-p/754858#M238145</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-07-18T15:17:32Z</dc:date>
    </item>
  </channel>
</rss>

