<?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: Change all date variables to first day of the month in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/352060#M23229</link>
    <description>&lt;P&gt;If you know the variables in question, you can define an array over them and loop through for resetting the values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset;
set dataset;
array datevars {*} startdate birthdate enddate datevar1-datevar3;
do i = 1 to dim(datevars);
  if datevars{i} &amp;lt;= intnx('month',datevars{i},0,'middle')
  then datevars{i} = intnx('month',datevars{i},0,'begin');
  else datevars{i} = intnx('month',datevars{i},0,'end');
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't know the names of the variables, you can extract their names from dictionary.columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name into :varnames seperated by ' '
from dictionary.columns
where
  upcase(memname) = 'DATASET' and upcase(libname) = 'LIB'
  and type = 'num' and format contains 'DDMMYY'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use &amp;amp;varnames in the array definition. Adapt the where condition to your needs with regard to the format names.&lt;/P&gt;</description>
    <pubDate>Fri, 21 Apr 2017 06:09:27 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-04-21T06:09:27Z</dc:date>
    <item>
      <title>Change all date variables to first day of the month</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351700#M23173</link>
      <description>&lt;P&gt;Folks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm currently writing a loading program to create a number of datasets. In total I'm creating 14 datasets and would thing I would like to do is convert any date variables I have to the first day of any specifc month.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, for a variable called newdate with one value being 12/4/1978, I would like to change the date to the 1/4/1978.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there any general way to include in my program a piece of code which converts all dates to the first of specifc month? I understand how to to this in each general dataset but would like something more effieicient if possible?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any information would be most welcome.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 14:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351700#M23173</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-04-20T14:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Change all date variables to first day of the month</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351703#M23174</link>
      <description>&lt;P&gt;Assuming your date varaibles are actually SAS date valued variables.&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; date = intnx('month',date,0,'b');&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;increments the month by 0 (same month) and uses the begining with the 'b' for alignment.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 14:26:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351703#M23174</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-04-20T14:26:18Z</dc:date>
    </item>
    <item>
      <title>Re: Change all date variables to first day of the month</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351704#M23175</link>
      <description>&lt;P&gt;To change newdate to the first of the month, use&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newdate = intnx('month',newdate,0,'begin');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;To automatically find all date variables in a dataset, fetch all records from dictionary.columns that are numeric and have a date format assigned.&lt;/P&gt;
&lt;P&gt;If you have been strict in using date formats, this might be quite easy.&lt;/P&gt;
&lt;P&gt;Then you could use data _null_ and call execute to create a data step dynamically to change the values.&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 14:28:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351704#M23175</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-20T14:28:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change all date variables to first day of the month</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351718#M23177</link>
      <description>&lt;P&gt;Folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;A slight deviation to what I've asked. Is it possible to amend the code so that if the date is closer to the end of the month the 31st or 30th the date will be converted to, and if it's closer to the start of the month the the 1st is used?&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 14:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351718#M23177</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-04-20T14:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Change all date variables to first day of the month</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351726#M23180</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116786"&gt;@Sean_OConnor&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Folks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A slight deviation to what I've asked. Is it possible to amend the code so that if the date is closer to the end of the month the 31st or 30th the date will be converted to, and if it's closer to the start of the month the the 1st is used?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This is also possible through the use of the &lt;A href="http://support.sas.com/documentation/cdl/en/lefunctionsref/69762/HTML/default/viewer.htm#p10v3sa3i4kfxfn1sovhi5xzxh8n.htm" target="_blank"&gt;intnx()&lt;/A&gt; function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if newdate &amp;lt;= intnx('month',newdate,0,'middle')
then newdate = intnx('month',newdate,0,'begin');
else newdate = intnx('month',newdate,0,'end');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 14:59:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351726#M23180</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-20T14:59:35Z</dc:date>
    </item>
    <item>
      <title>Re: Change all date variables to first day of the month</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351745#M23184</link>
      <description>&lt;P&gt;Thanks for this Kurt.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Just a quick question. As I'm new enough to SAS is it possible to extend this piece of code to referenece more than one variable?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if newdate &amp;lt;= intnx('month',newdate,0,'middle')
then newdate = intnx('month',newdate,0,'begin');
else newdate = intnx('month',newdate,0,'end');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The below doesn't work but is what I'm trying to do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if cease or accountsfrom or accountsto &amp;lt;= intnx('month',cease or accountsfrom or accountsto,0,'middle')
then cease or accountsfrom or accountsto = intnx('month',cease or accountsfrom or accountsto,0,'begin');
else cease or accountsfrom or accountsto = intnx('month',cease or accountsfrom or accountsto,0,'end');&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 20 Apr 2017 15:28:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351745#M23184</guid>
      <dc:creator>Sean_OConnor</dc:creator>
      <dc:date>2017-04-20T15:28:22Z</dc:date>
    </item>
    <item>
      <title>Re: Change all date variables to first day of the month</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351748#M23185</link>
      <description>&lt;P&gt;Another solution that does not involve the INTCK function:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;newdate = mdy (month(date),1,year(date));&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 15:31:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351748#M23185</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2017-04-20T15:31:56Z</dc:date>
    </item>
    <item>
      <title>Re: Change all date variables to first day of the month</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351920#M23202</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116786"&gt;@Sean_OConnor&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks for this Kurt.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just a quick question. As I'm new enough to SAS is it possible to extend this piece of code to referenece more than one variable?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if newdate &amp;lt;= intnx('month',newdate,0,'middle')
then newdate = intnx('month',newdate,0,'begin');
else newdate = intnx('month',newdate,0,'end');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The below doesn't work but is what I'm trying to do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if cease or accountsfrom or accountsto &amp;lt;= intnx('month',cease or accountsfrom or accountsto,0,'middle')
then cease or accountsfrom or accountsto = intnx('month',cease or accountsfrom or accountsto,0,'begin');
else cease or accountsfrom or accountsto = intnx('month',cease or accountsfrom or accountsto,0,'end');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, you can't reference variables in this manner. You can create an array to loop through multiple variables and do the conversion though.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 20 Apr 2017 20:47:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/351920#M23202</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-20T20:47:04Z</dc:date>
    </item>
    <item>
      <title>Re: Change all date variables to first day of the month</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/352060#M23229</link>
      <description>&lt;P&gt;If you know the variables in question, you can define an array over them and loop through for resetting the values:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data dataset;
set dataset;
array datevars {*} startdate birthdate enddate datevar1-datevar3;
do i = 1 to dim(datevars);
  if datevars{i} &amp;lt;= intnx('month',datevars{i},0,'middle')
  then datevars{i} = intnx('month',datevars{i},0,'begin');
  else datevars{i} = intnx('month',datevars{i},0,'end');
end;
drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you don't know the names of the variables, you can extract their names from dictionary.columns:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
select name into :varnames seperated by ' '
from dictionary.columns
where
  upcase(memname) = 'DATASET' and upcase(libname) = 'LIB'
  and type = 'num' and format contains 'DDMMYY'
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now you can use &amp;amp;varnames in the array definition. Adapt the where condition to your needs with regard to the format names.&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2017 06:09:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Change-all-date-variables-to-first-day-of-the-month/m-p/352060#M23229</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-04-21T06:09:27Z</dc:date>
    </item>
  </channel>
</rss>

