<?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: Retain for all ID in a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379087#M276861</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The purpose would be to understand RG movements (stays same, moves up or down) by month and feed into reporting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
    <pubDate>Tue, 25 Jul 2017 15:42:10 GMT</pubDate>
    <dc:creator>PetePatel</dc:creator>
    <dc:date>2017-07-25T15:42:10Z</dc:date>
    <item>
      <title>Retain for all ID in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379049#M276854</link>
      <description>&lt;P&gt;Hello SAS Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a large dataset with c. 300 months and c. 5k ID's that looks&amp;nbsp;like the first 3 variables below (ID, month and RG). The aim is to get to the RG_mmmyy state as shown by the following 5 variables so that the RG is retained for all ID's (past and future) depending on the month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;Month&lt;/TD&gt;&lt;TD&gt;RG&lt;/TD&gt;&lt;TD&gt;RG_Jan12&lt;/TD&gt;&lt;TD&gt;RG_J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2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Jan-14&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Jan-15&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;Jan-16&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;.&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can you please help me to build the code efficiently so this works inside a macro (unless there is a simpler way)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;Pete&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 14:54:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379049#M276854</guid>
      <dc:creator>PetePatel</dc:creator>
      <dc:date>2017-07-25T14:54:36Z</dc:date>
    </item>
    <item>
      <title>Re: Retain for all ID in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379053#M276855</link>
      <description>&lt;P&gt;What's the logic behind the RG_Jan variables?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 14:57:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379053#M276855</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-25T14:57:20Z</dc:date>
    </item>
    <item>
      <title>Re: Retain for all ID in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379057#M276856</link>
      <description>&lt;P&gt;It sounds like you want to create variables whose names depend on the value of varaibles in your data. &amp;nbsp;That is normally something that you would do with PROC TRANSPOSE. &amp;nbsp;But your posted example data does not really make any sense.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 14:59:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379057#M276856</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-25T14:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Retain for all ID in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379059#M276857</link>
      <description>&lt;P&gt;I'm not sure this is a good idea, but it's reasonably straightforward to accomplish:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc transpose data=have prefix=RG_ out=results (drop=_name_);&lt;/P&gt;
&lt;P&gt;var RG;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;id month;&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;merge have results;&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;It's untested code, but looks about right.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 15:01:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379059#M276857</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-25T15:01:38Z</dc:date>
    </item>
    <item>
      <title>Re: Retain for all ID in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379060#M276858</link>
      <description>&lt;P&gt;Well, I would first ask why. &amp;nbsp;What benefit is there going from a structure with few fixed variable names (makes programming easier) and small dataset size 3 * obs and transforming this into a dataset here variable names could be all kinds of things, and data is vastly blown up to obs * obs? &amp;nbsp;There seems to be no gain in any way.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Technically you can do it, with arrays, first take distinct values of month, then transpose that up, merge this onto the data you have and retain the various parts. &amp;nbsp;Alternatively, transpose the data you have up, and then merge it back to the original data on id=id. &amp;nbsp;Eg.&lt;/P&gt;
&lt;PRE&gt;proc transpose data=have out=t prefix=rg_;
  by id;
  var rg;
  id month;
run;
data want;
  merge have want;
  by id;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jul 2017 15:02:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379060#M276858</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-07-25T15:02:16Z</dc:date>
    </item>
    <item>
      <title>Re: Retain for all ID in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379064#M276859</link>
      <description>&lt;P&gt;Apologies, should have been clearer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The RG_mmmyy variables are the desired variables that I would like to create and link back to month and RG (variables I already have).&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 15:04:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379064#M276859</guid>
      <dc:creator>PetePatel</dc:creator>
      <dc:date>2017-07-25T15:04:13Z</dc:date>
    </item>
    <item>
      <title>Re: Retain for all ID in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379067#M276860</link>
      <description>Apologies, should have been clearer. The RG_mmmyy variables are the desired variables that I would like to create and link back to month and RG (variables I already have).</description>
      <pubDate>Tue, 25 Jul 2017 15:05:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379067#M276860</guid>
      <dc:creator>PetePatel</dc:creator>
      <dc:date>2017-07-25T15:05:22Z</dc:date>
    </item>
    <item>
      <title>Re: Retain for all ID in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379087#M276861</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The purpose would be to understand RG movements (stays same, moves up or down) by month and feed into reporting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 15:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379087#M276861</guid>
      <dc:creator>PetePatel</dc:creator>
      <dc:date>2017-07-25T15:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: Retain for all ID in a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379088#M276862</link>
      <description>&lt;P&gt;Thank you very much&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jul 2017 15:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Retain-for-all-ID-in-a-macro/m-p/379088#M276862</guid>
      <dc:creator>PetePatel</dc:creator>
      <dc:date>2017-07-25T15:42:46Z</dc:date>
    </item>
  </channel>
</rss>

