<?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: Help with More Efficient Code in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/271135#M58294</link>
    <description>Thank you! This helped!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 17 May 2016 22:26:55 GMT</pubDate>
    <dc:creator>kiwi</dc:creator>
    <dc:date>2016-05-17T22:26:55Z</dc:date>
    <item>
      <title>Help with More Efficient Code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/270807#M58244</link>
      <description>&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;I'm trying to figure out a way to use a loop and/or macro to simplify this code where I'm setting up 99 columns (ExposureUnits01, ExposureUnits02, etc.)&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;

CREATE TABLE EXAMPLE02 AS

SELECT

Policy,

UNITS01* ExposureCount01 as ExposureUnits01,

UNITS02* ExposureCount02 as ExposureUnits02,

UNITS03* ExposureCount03 as ExposureUnits03,

UNITS04* ExposureCount04 as ExposureUnits04,

/*(… ETC…)*/

UNITS99* ExposureCount99 as ExposureUnits99

FROM EXAMPLE01;

QUIT;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 May 2016 22:37:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/270807#M58244</guid>
      <dc:creator>kiwi</dc:creator>
      <dc:date>2016-05-16T22:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help with More Efficient Code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/270818#M58245</link>
      <description>&lt;P&gt;This won't make the program run any faster, but it can simplify your life as a programmer. &amp;nbsp;Consider a macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%macro all99;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%local i;&lt;/P&gt;
&lt;P&gt;%do i=1 %to 99;&lt;/P&gt;
&lt;P&gt;, UNITS%sysfunc(putn(&amp;amp;i, z2)) * ExposureCount%sysfunc(putn(&amp;amp;i, z2)) as ExposureUnits%sysfunc(putn(&amp;amp;i, z2))&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%mend all99;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then call the macro in the middle of the SELECT statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table example02 as select policy, %all99 from example01;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The leading zeros complicates things a bit. &amp;nbsp;It would be simpler if you wanted ExposureUnits1-ExposureUnits99 instead of ExposureUnits01-ExposureUnits99.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'll have to try it to verify that it works ... I can't test it right now. &amp;nbsp;But if there are any issues they will be straightforward to fix.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 16 May 2016 23:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/270818#M58245</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-05-16T23:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: Help with More Efficient Code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/270862#M58248</link>
      <description>My simple answer is, don't. &lt;BR /&gt;Examples like this show how awkward ig is to work with column heavy (aka long) table layout. &lt;BR /&gt;Transpose your table and there is only need for a single assignment.</description>
      <pubDate>Tue, 17 May 2016 02:37:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/270862#M58248</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-05-17T02:37:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help with More Efficient Code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/270909#M58250</link>
      <description>&lt;P&gt;Firstly, let me say this quite clearly, Macro language does Not make code more efficient! &amp;nbsp;If anything it merely obfuscates the code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Secondly, I totally agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13674"&gt;@LinusH﻿&lt;/a&gt;, it is never a good idea to create many variables, this number may change over time, so your structure will keep changing. &amp;nbsp;It is far easier to program with observations where structure does not change each run. &amp;nbsp;Also to note on this, SQL is a language designed to work with normalised data, so this type of processing is really not good to do with SQL. &amp;nbsp;In SAS you have arrays, but even then I would suggest a new observation per data item rather than column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So get yourself a dataset which has one observation per item:&lt;/P&gt;
&lt;P&gt;POLICY &amp;nbsp; EXPOSURE_EVENT &amp;nbsp; EXPOSURE_COUNT &amp;nbsp;EXPOSURE_UNITS&lt;/P&gt;
&lt;P&gt;XYZ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; abc&lt;/P&gt;
&lt;P&gt;XYZ &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 2 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 87 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;abc&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You will see the above structure would not change no matter how many events there are - makes your programming easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 09:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/270909#M58250</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-17T09:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: Help with More Efficient Code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/271135#M58294</link>
      <description>Thank you! This helped!&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 17 May 2016 22:26:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/271135#M58294</guid>
      <dc:creator>kiwi</dc:creator>
      <dc:date>2016-05-17T22:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Help with More Efficient Code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/271136#M58295</link>
      <description>&lt;P&gt;Thank you.&amp;nbsp; I was trying to get away from making&amp;nbsp;hundreds of&amp;nbsp;columns, but I don't think I can avoid it.&amp;nbsp; Each policy will have 120 years of mortality rates.&amp;nbsp; I think I'd be worse off by transposing it?&amp;nbsp; I'll think about it though.&amp;nbsp; Still new to programming so I appreciate the help!&lt;/P&gt;</description>
      <pubDate>Tue, 17 May 2016 22:32:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/271136#M58295</guid>
      <dc:creator>kiwi</dc:creator>
      <dc:date>2016-05-17T22:32:27Z</dc:date>
    </item>
    <item>
      <title>Re: Help with More Efficient Code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/271207#M58304</link>
      <description>&lt;P&gt;Of course you can avoid it. &amp;nbsp;Databasing, and programming have been around for 40 odd years using normalised data. &amp;nbsp;Understand your data, and how you want to work with, then strcuture it in a way that makes your life easiest, this is the core process of a programmer.&lt;/P&gt;</description>
      <pubDate>Wed, 18 May 2016 08:04:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Help-with-More-Efficient-Code/m-p/271207#M58304</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-05-18T08:04:54Z</dc:date>
    </item>
  </channel>
</rss>

