<?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: Creating variables with proc sql between specific dates in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79711#M256570</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Where is for filtering the whole result set, so it's probably not what you are looking for.&lt;/P&gt;&lt;P&gt;Take a look at CASE, which you could use in the Select statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 12 Sep 2013 08:29:39 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2013-09-12T08:29:39Z</dc:date>
    <item>
      <title>Creating variables with proc sql between specific dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79710#M256569</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;I am new to the SAS programming world and was hoping someone could help me.&lt;/P&gt;&lt;P&gt;I want to create a new variable in SAS where I ask sas to take the values of variable "performance", but only between a specific time interval, between 31/12//2009 and 31/12/2010 and put this variable in a new column called performance2010. I do not want sas to sum or subract the values of the variable performance. I simply want it to create a new column where only the values of performance from 2010 are in it. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This is my code:&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE Performance AS&lt;/P&gt;&lt;P&gt;SELECT*&lt;/P&gt;&lt;P&gt;FROM Return&lt;/P&gt;&lt;P&gt;WHERE Performance = ToDate Where ToDate Between dmy(31, 12, 2009) and dmy(31, 12, 2010) AS Performance2010;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;"ToDate" is my date variable and in my data is written by day-months-years&lt;/P&gt;&lt;P&gt;As you can see the second last line is incorrect, but I do not know how to write the last piece of code&lt;/P&gt;&lt;P&gt;Can somehelp me? I would really appreciate it&lt;/P&gt;&lt;P&gt;Thanks &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 07:36:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79710#M256569</guid>
      <dc:creator>Bruce123</dc:creator>
      <dc:date>2013-09-12T07:36:17Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables with proc sql between specific dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79711#M256570</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Where is for filtering the whole result set, so it's probably not what you are looking for.&lt;/P&gt;&lt;P&gt;Take a look at CASE, which you could use in the Select statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 08:29:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79711#M256570</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2013-09-12T08:29:39Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables with proc sql between specific dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79712#M256571</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Being a bit rusty on my date/time functions, and being unable to view your current data set, may I suggest the following.&amp;nbsp; I have taken the liberty of renaming the various keywords to better describe your case since the syntax was wrong in the example you gave.&amp;nbsp; Also, since you were ambiguous as to exactly how you'd like it, I've done it two ways:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* If you really want to create a subset of the original table, do the following */&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE Your_New_Table AS&lt;/P&gt;&lt;P&gt;SELECT *,&amp;nbsp; old_performance_variable AS new_performance_variable&lt;/P&gt;&lt;P&gt;FROM your_original_table&lt;/P&gt;&lt;P&gt;WHERE ToDate Between dmy(31,12,2009) and dmy(31,12,2010);&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/* If you really want to have the values be missing when performance is not between your two dates, do the following.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE Your_New_Table AS&lt;/P&gt;&lt;P&gt;SELECT *,&amp;nbsp; &lt;/P&gt;&lt;P&gt;CASE&lt;/P&gt;&lt;P&gt; WHEN ToDate BETWEEN dmy(31,12,2009) AND dmy(31,12,2010) THEN old_performance_variable&lt;/P&gt;&lt;P&gt; ELSE . /* have I forgotten how to do missing values nicely? */&lt;/P&gt;&lt;P&gt; END AS new_performance_variable&lt;/P&gt;&lt;P&gt;FROM your_original_table&lt;SPAN style="font-size: 10pt; line-height: 1.5em;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 08:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79712#M256571</guid>
      <dc:creator>DJM_SAS</dc:creator>
      <dc:date>2013-09-12T08:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables with proc sql between specific dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79713#M256572</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Thanks that helped me a lot, and SAS is now completing the procedure.&lt;/P&gt;&lt;P&gt;But one more thing:&lt;/P&gt;&lt;P&gt;I also want to get two other date intervals. One fore 2011 (todate between dmy(31, 12, 2010) and dmy(31, 12 2011)) and 2012 (todate between dmy(31, 12, 2011) and dmy(31, 12, 2012).&lt;/P&gt;&lt;P&gt;Is it possible to do this with the same dataset and in the code-procedure. &lt;/P&gt;&lt;P&gt;I've tried this but Sas only takes one of the dateinterval e.g. it only takes 2011 instead of 2010 and 2011&lt;/P&gt;&lt;P&gt;Could you help out here aswell. I would really &lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;appreciate &lt;/SPAN&gt;it&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 09:43:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79713#M256572</guid>
      <dc:creator>Bruce123</dc:creator>
      <dc:date>2013-09-12T09:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables with proc sql between specific dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79714#M256573</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Bruce,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming you're using the second of my two pieces of code, you can generate two extra variables by adding in new case statements like so:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE Your_New_Table AS&lt;/P&gt;&lt;P&gt;SELECT *,&amp;nbsp; &lt;/P&gt;&lt;P&gt;CASE&lt;/P&gt;&lt;P&gt; WHEN ToDate BETWEEN dmy(31,12,2009) AND dmy(31,12,2010) THEN old_performance_variable&lt;/P&gt;&lt;P&gt; ELSE . &lt;/P&gt;&lt;P&gt; END AS new_performance_variable,&lt;/P&gt;&lt;P&gt;CASE&lt;/P&gt;&lt;P&gt; WHEN ToDate BETWEEN dmy(31,12,2010) AND dmy(31,12,2011) THEN old_performance_variable&lt;/P&gt;&lt;P&gt; ELSE . &lt;/P&gt;&lt;P&gt; END AS new_performance_variable2,&lt;/P&gt;&lt;P&gt;CASE&lt;/P&gt;&lt;P&gt; WHEN ToDate BETWEEN dmy(31,12,2011) AND dmy(31,12,2012) THEN old_performance_variable&lt;/P&gt;&lt;P&gt; ELSE . &lt;/P&gt;&lt;P&gt; END AS new_performance_variable3&lt;/P&gt;&lt;P&gt;FROM your_original_table&lt;SPAN style="font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Note: There's no comma after new_performance_variable3, but there is after 1 and 2.&lt;/P&gt;&lt;P&gt;Alternatively, if you want just one new variable, which includes information if any of those conditions are met and missing otherwise, you can extend out the original case clause like so:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PROC SQL;&lt;/P&gt;&lt;P&gt;CREATE TABLE Your_New_Table AS&lt;/P&gt;&lt;P&gt;SELECT *,&amp;nbsp; &lt;/P&gt;&lt;P&gt;CASE&lt;/P&gt;&lt;P&gt; WHEN ToDate BETWEEN dmy(31,12,2009) AND dmy(31,12,2010) THEN old_performance_variable&lt;/P&gt;&lt;P&gt; WHEN ToDate BETWEEN dmy(31,12,2010) AND dmy(31,12,2011) THEN old_performance_variable&lt;/P&gt;&lt;P&gt; WHEN ToDate BETWEEN dmy(31,12,2011) AND dmy(31,12,2012) THEN old_performance_variable&lt;/P&gt;&lt;P&gt; ELSE . &lt;/P&gt;&lt;P&gt; END AS new_performance_variable&lt;/P&gt;&lt;P&gt;FROM your_original_table&lt;SPAN style="font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;QUIT;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm off to bed for the night, but if you were using the other code framework i prepared instead, it would require some boolean logic (AND and OR clauses with some bracketing) in the where statement.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 12:28:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79714#M256573</guid>
      <dc:creator>DJM_SAS</dc:creator>
      <dc:date>2013-09-12T12:28:53Z</dc:date>
    </item>
    <item>
      <title>Re: Creating variables with proc sql between specific dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79715#M256574</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Yes, I was using the second piece of your code.&lt;/P&gt;&lt;P&gt;Thanks very much for your help. You are my hero &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;P&gt;Good night &lt;img id="smileywink" class="emoticon emoticon-smileywink" src="https://communities.sas.com/i/smilies/16x16_smiley-wink.png" alt="Smiley Wink" title="Smiley Wink" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 12 Sep 2013 12:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-variables-with-proc-sql-between-specific-dates/m-p/79715#M256574</guid>
      <dc:creator>Bruce123</dc:creator>
      <dc:date>2013-09-12T12:50:31Z</dc:date>
    </item>
  </channel>
</rss>

