<?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: Create new variable without creating new data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431354#M106690</link>
    <description>&lt;P&gt;Not really, once you're creating new variables it will recreate the data. SQL seems like it doesn't using insert, but it still does as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What type of efficiency are you trying to gain here? Are you trying to speed up your processing to reduce wait time while programming or your time?&lt;/P&gt;</description>
    <pubDate>Fri, 26 Jan 2018 17:23:35 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-01-26T17:23:35Z</dc:date>
    <item>
      <title>Create new variable without creating new data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431347#M106688</link>
      <description>&lt;P&gt;I have a data set with hundreds of variables and millions of observations. I need to constantly modify this data (about 30 GB). For example, creating a new variable by take sum of two existing variables, etc. I used the following data step:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data mydata;&lt;/P&gt;&lt;P&gt;&amp;nbsp; set mydata;&lt;/P&gt;&lt;P&gt;&amp;nbsp; new_var=var1+var2;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My understanding is that even the data has the same name, but SAS is creating a new data based on the original one. This will take longer time every time since the data size is large. I am wondering if there is other more efficient ways to add new variable to existing data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 16:58:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431347#M106688</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2018-01-26T16:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable without creating new data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431354#M106690</link>
      <description>&lt;P&gt;Not really, once you're creating new variables it will recreate the data. SQL seems like it doesn't using insert, but it still does as well.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What type of efficiency are you trying to gain here? Are you trying to speed up your processing to reduce wait time while programming or your time?&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 17:23:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431354#M106690</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-26T17:23:35Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable without creating new data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431363#M106693</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I have a data set with hundreds of variables and millions of observations. I need to constantly modify this data (about 30 GB). For example, creating a new variable by take sum of two existing variables, etc. I used the following data step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You might look into WHY you have to "constantly modify" existing data. Doing so is often indicative of poor process planning.&lt;/P&gt;
&lt;P&gt;Are the new variables used frequently or just once?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If for a specific analysis task it is often preferable to extract only the variables needed and then add the variables just for that task. Such as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data analysistask;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set mydata (keep= var1 var2 &amp;lt;other variables needed for the specific task&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; new_var = sum(var1, var2); /* or var1+var2 if you know why there is a difference between SUM and +*/&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;and use the analysistask set for the next steps.&lt;/P&gt;
&lt;P&gt;Another approach instead of creating a huge data set might be to create a view from the existing data. The view basically has the code to create stuff from the current version of the data set and trades execution time for storage space&lt;/P&gt;
&lt;P&gt;Data analysistask /view=analysistask;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set mydata (keep= var1 var2 &amp;lt;other variables needed for the specific task&amp;gt;);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; new_var = sum(var1, var2); /* or var1+var2 if you know why there is a difference between SUM and +*/&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Creates a reference that will read the current set mydata.&lt;/P&gt;
&lt;P&gt;Then something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Proc Reg data=analysistask;&lt;/P&gt;
&lt;P&gt;&amp;lt;proc options&amp;gt;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;in effect reads Mydata, adds the new_var and then uses the result in the procedure. Which will be slower to execute but doesn't have the opportunity to overwrite existing data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW habitual use of the structure:&lt;/P&gt;
&lt;P&gt;Data mydata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set mydata;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;lt;modification code&amp;gt;&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;will eventually lead to case where one or more variables has values you do not expect and you will have a lot of fun trying to recover data.&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 17:47:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431363#M106693</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-26T17:47:39Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable without creating new data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431466#M106734</link>
      <description>&lt;P&gt;Thanks for the reply! Good thoughts!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 22:08:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431466#M106734</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2018-01-26T22:08:33Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable without creating new data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431469#M106735</link>
      <description>&lt;P&gt;want to reduce waiting time&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 22:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431469#M106735</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2018-01-26T22:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable without creating new data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431474#M106737</link>
      <description>&lt;P&gt;I don't know enough to do that &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; But the approaches I use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. hash tables for joins, assuming you have enough memory&lt;/P&gt;
&lt;P&gt;2. Limit the number of obs when testing code, I'll usually only work with about 1-2 million observations, enough to have all the things I'm likely to encounter. If you use that, be very careful with sorts - especially ones without OUT data sets. It will create a data set with only 1000000 records.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;option obs=1000000;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;3. Make sure &amp;nbsp;to do multiple steps together rather than have 5 different data steps that each create a single variable.&lt;/P&gt;
&lt;P&gt;4. Create indexes to make sure the usage afterwards is quick.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/84484"&gt;@sasecn&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;want to reduce waiting time&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 22:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431474#M106737</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-01-26T22:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Create new variable without creating new data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431475#M106738</link>
      <description>&lt;P&gt;Thanks for the ideas!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 22:36:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-new-variable-without-creating-new-data/m-p/431475#M106738</guid>
      <dc:creator>sasecn</dc:creator>
      <dc:date>2018-01-26T22:36:55Z</dc:date>
    </item>
  </channel>
</rss>

