<?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: Convert Char 6. to Date9. (to beginning and end of month) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429424#M106077</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/101199"&gt;@Estelle&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I&amp;nbsp;must be missing something. I am getting nulls as (.) for yrmo, beg_cov_dt, and end_cov_dt., using this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname TO '/sasdata3/MI/projects/valuequest/production/output';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data TO.mbrs_dt_test;&lt;BR /&gt;set TO.mbrshp_0716to0617_final_test;&lt;BR /&gt;YRMO = YRMO;&lt;BR /&gt;BEG_COV_DT = INPUT(YRMO,YYMMN6.);&lt;BR /&gt;PUT BEG_COV_DT DATE9.;&lt;BR /&gt;END_COV_DT = INTNX('MONTH',BEG_COV_DT,0,'E');&lt;BR /&gt;PUT END_COV_DT DATE9.;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(I assume you meant to set YRMO equal to itself?)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Setting a variable to itself will not do anything.&lt;/P&gt;
&lt;P&gt;I suspect that YRMO is a numeric variable instead of character string. So you need to tell SAS how to convert it to character strings for the INPUT() function to work on.&amp;nbsp; Otherwise it will use BEST12. format to convert it to something like '&amp;nbsp; &amp;nbsp; &amp;nbsp; 201706' and then when you read just the first 6 characters all you are reading are spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;BEG_COV_DT = INPUT(put(YRMO,Z6.),YYMMN6.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 21 Jan 2018 00:04:27 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-01-21T00:04:27Z</dc:date>
    <item>
      <title>Convert Char 6. to Date9. (to beginning and end of month)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429322#M106036</link>
      <description>&lt;P&gt;SAS Hive Mind:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a 6 length character variable, yrmo, that represents a date like '201701'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to create two variables from yrmo in sasdate9. formats:&lt;/P&gt;&lt;P&gt;Beg_date_cov&lt;/P&gt;&lt;P&gt;eff_date_cov&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Where beg_date_cov would start at the first of the month like: '01JAN20167'&lt;/P&gt;&lt;P&gt;And end_date_cov would be the last day of the month like: '31JAN2017'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried numerous iterations of code involving intnx, put, input, format, informat, 'b', 'e': I won't bother writing all iterations that I've tried here since there many and well, they're all wrong.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thoughts?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 23:35:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429322#M106036</guid>
      <dc:creator>Estelle</dc:creator>
      <dc:date>2018-01-19T23:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Char 6. to Date9. (to beginning and end of month)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429326#M106039</link>
      <description>&lt;PRE&gt;data example;
   x='201701';
   xdate = input(x,yymmn6.);
   put xdate date9.; /* note that SAS Assigns first of month by default*/
   endofmonth= intnx('month',xdate,0,'E');
   put endofmonth date9.;
run;&lt;/PRE&gt;
&lt;P&gt;add format statements if you want them permanently associated with the variables. Look in the log for the result of the puts if you don't use them much.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2018 23:44:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429326#M106039</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-01-19T23:44:01Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Char 6. to Date9. (to beginning and end of month)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429418#M106073</link>
      <description>&lt;P&gt;I&amp;nbsp;must be missing something. I am getting nulls as (.) for yrmo, beg_cov_dt, and end_cov_dt., using this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;libname TO '/sasdata3/MI/projects/valuequest/production/output';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data TO.mbrs_dt_test;&lt;BR /&gt;set TO.mbrshp_0716to0617_final_test;&lt;BR /&gt;YRMO = YRMO;&lt;BR /&gt;BEG_COV_DT = INPUT(YRMO,YYMMN6.);&lt;BR /&gt;PUT BEG_COV_DT DATE9.;&lt;BR /&gt;END_COV_DT = INTNX('MONTH',BEG_COV_DT,0,'E');&lt;BR /&gt;PUT END_COV_DT DATE9.;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(I assume you meant to set YRMO equal to itself?)&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 22:51:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429418#M106073</guid>
      <dc:creator>Estelle</dc:creator>
      <dc:date>2018-01-20T22:51:08Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Char 6. to Date9. (to beginning and end of month)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429422#M106076</link>
      <description>&lt;P&gt;Are you sure it's a character field. Here is your example presented two ways: first assuming it is a character field, then assuming it's a numeric field:&lt;/P&gt;
&lt;PRE&gt;libname to '/folders/myfolders';
data to.mbrshp_0716to0617_final_test;
  input yrmo $;
  cards;
201702
201605
;

Data TO.mbrs_dt_test;
  set TO.mbrshp_0716to0617_final_test;
  format BEG_COV_DT END_COV_DT date9.;
  BEG_COV_DT = INPUT(YRMO,YYMMN6.);
  PUT BEG_COV_DT;
  END_COV_DT = INTNX('MONTH',BEG_COV_DT,0,'E');
  PUT END_COV_DT;
RUN;

data to.mbrshp_0716to0617_final_test;
  input yrmo;
  cards;
201702
201605
;

Data TO.mbrs_dt_test;
  set TO.mbrshp_0716to0617_final_test;
  format BEG_COV_DT END_COV_DT date9.;
  BEG_COV_DT = INPUT(put(YRMO,6.),YYMMN6.);
  PUT BEG_COV_DT;
  END_COV_DT = INTNX('MONTH',BEG_COV_DT,0,'E');
  PUT END_COV_DT;
RUN;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Jan 2018 23:15:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429422#M106076</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-01-20T23:15:31Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Char 6. to Date9. (to beginning and end of month)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429424#M106077</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/101199"&gt;@Estelle&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;I&amp;nbsp;must be missing something. I am getting nulls as (.) for yrmo, beg_cov_dt, and end_cov_dt., using this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;libname TO '/sasdata3/MI/projects/valuequest/production/output';&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data TO.mbrs_dt_test;&lt;BR /&gt;set TO.mbrshp_0716to0617_final_test;&lt;BR /&gt;YRMO = YRMO;&lt;BR /&gt;BEG_COV_DT = INPUT(YRMO,YYMMN6.);&lt;BR /&gt;PUT BEG_COV_DT DATE9.;&lt;BR /&gt;END_COV_DT = INTNX('MONTH',BEG_COV_DT,0,'E');&lt;BR /&gt;PUT END_COV_DT DATE9.;&lt;BR /&gt;RUN;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(I assume you meant to set YRMO equal to itself?)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Setting a variable to itself will not do anything.&lt;/P&gt;
&lt;P&gt;I suspect that YRMO is a numeric variable instead of character string. So you need to tell SAS how to convert it to character strings for the INPUT() function to work on.&amp;nbsp; Otherwise it will use BEST12. format to convert it to something like '&amp;nbsp; &amp;nbsp; &amp;nbsp; 201706' and then when you read just the first 6 characters all you are reading are spaces.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;BEG_COV_DT = INPUT(put(YRMO,Z6.),YYMMN6.);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 21 Jan 2018 00:04:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/429424#M106077</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-01-21T00:04:27Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Char 6. to Date9. (to beginning and end of month)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/430225#M106349</link>
      <description>&lt;P&gt;It was a character. I am not sure what I was doing wrong but it does work now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have adopted a new problem with this solution, it now write all of these dates to the log. It's about 65 million rows so the log gets too big to open, I can only see it in unix.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any idea on how an option to suppress that? I can probably&amp;nbsp;look around until I find some option to make that happen... or I will just post another issue here in SAS communities &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 00:24:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/430225#M106349</guid>
      <dc:creator>Estelle</dc:creator>
      <dc:date>2018-01-24T00:24:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Char 6. to Date9. (to beginning and end of month)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/430232#M106350</link>
      <description>&lt;P&gt;You're getting all of those date written to the log because of the two put statements you have in your code. Just remove them!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 00:51:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/430232#M106350</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2018-01-24T00:51:12Z</dc:date>
    </item>
    <item>
      <title>Re: Convert Char 6. to Date9. (to beginning and end of month)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/430724#M106483</link>
      <description>&lt;P&gt;Right! Put statements.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;They put stuff in the log, I knew that!&lt;/P&gt;</description>
      <pubDate>Wed, 24 Jan 2018 23:43:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-Char-6-to-Date9-to-beginning-and-end-of-month/m-p/430724#M106483</guid>
      <dc:creator>Estelle</dc:creator>
      <dc:date>2018-01-24T23:43:09Z</dc:date>
    </item>
  </channel>
</rss>

