<?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: Need help to convert character Datetime into 01MMMyy in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501035#M133537</link>
    <description>&lt;P&gt;Start by giving us a usable example of your "source data".&lt;/P&gt;
&lt;P&gt;If it's a dataset, use the macro from my second footnote and convert it to a data step, which you then can post according to the hints in my third footnote.&lt;/P&gt;
&lt;P&gt;If it is in an external file, post a sample of that external file, either as attachment, or by copy-pasting it into a window opened with the {i} button.&lt;/P&gt;</description>
    <pubDate>Wed, 03 Oct 2018 06:45:50 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2018-10-03T06:45:50Z</dc:date>
    <item>
      <title>Need help to convert character Datetime into 01MMMyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501023#M133530</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am seeking for help to convert the actual sas DATETIME into 01MmmYY&lt;/P&gt;&lt;P&gt;For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want my result to be like&lt;/P&gt;&lt;P&gt;01Jan06&lt;/P&gt;&lt;P&gt;01Dec17&lt;/P&gt;&lt;P&gt;Note: Day is always 01 regardless of the actual date.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My original value is in datetime format below:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #424242; font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #f1efef; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;1-Jan-2015&amp;nbsp;8:00&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #424242; font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #f1efef; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;Can it be done in one line of statement? It will be put in "WHERE" clause so i do not want to create a new variable.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #424242; font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #f1efef; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;Initially, my source data is always in Jan2017 Feb2017 Mar2017 format. However, there are 4 letters month recently and i have to change my logic.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #424242; font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #f1efef; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;My original where clause filter is as below:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #424242; font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #f1efef; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;where put(input(cats('01',scan(file_source,1,'.')),date9.), yymmn6.) eq "&amp;amp;Period";&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #424242; font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #f1efef; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;However, I am now taking another column that is character datetime: 1-Jan-2015&amp;nbsp;8:00&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #424242; font-family: Roboto, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 13px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: nowrap; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #f1efef; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;I want my result to be always&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;01Jan06&lt;/P&gt;&lt;P&gt;01Dec17&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My updated but not working code for that is as below&lt;/P&gt;&lt;P&gt;where put(input(cats('01',scan(scan(scan(lt_date,1,' '),-2,'-'),1,'-'),scan(scan(scan(lt_date,1,' '),-2,'-'),-1,'-20')))) eq "&amp;amp;Period"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error the 2nd last or 3rd last closing bracket and expecting an EQ.&lt;BR /&gt;&lt;BR /&gt;Suggestions and advice are very much appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 04:49:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501023#M133530</guid>
      <dc:creator>WorkingMan</dc:creator>
      <dc:date>2018-10-03T04:49:35Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to convert character Datetime into 01MMMyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501031#M133535</link>
      <description>&lt;P&gt;Not too sure I undertand where the issue is , but his works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data t;
  c='1-Jan-2015 8:00';
  if catt('01',scan(c,2),scan(c,3)) ='01Jan2015' then putlog 'Correct';
run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 05:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501031#M133535</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-10-03T05:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to convert character Datetime into 01MMMyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501035#M133537</link>
      <description>&lt;P&gt;Start by giving us a usable example of your "source data".&lt;/P&gt;
&lt;P&gt;If it's a dataset, use the macro from my second footnote and convert it to a data step, which you then can post according to the hints in my third footnote.&lt;/P&gt;
&lt;P&gt;If it is in an external file, post a sample of that external file, either as attachment, or by copy-pasting it into a window opened with the {i} button.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 06:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501035#M133537</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-03T06:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to convert character Datetime into 01MMMyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501042#M133541</link>
      <description>&lt;P&gt;Your post is very confusing and contradictory.&amp;nbsp; Please start by posting some example test data in the form of a datastep:&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will illustrate what you actually have - that way we can see if your data is dates or characters etc. and avoids the contradictions, for example you say "&lt;/P&gt;
&lt;P&gt;My original value is in datetime format below:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1-Jan-2015&amp;nbsp;8:00&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;" - however then proceed to show code which is concatenating 01 to it which indicates that is not your value at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Next up show what you want out from that test data.&amp;nbsp; For instance, explain (if it is character as seems to be the case from some of what you post) why the date is kept as character - which is a very unusable format for dates/times.&amp;nbsp; Reading in the data, or first process should be to convert dates and times to numeric actual dates and times so they are easy to work with, and before you say "but they need to look like mmyyy" - this is what formats are for, a numeric date variable can be fomatted in many ways without changing the underlying data.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In terms of the final lines of your post, why do you want mixed case month?&amp;nbsp; I don't recall a SAS format which will do that for you, however if you really have to then simply:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;want=put(have,date9.);
substr(want,4,2)=lowcase(substr(want,4,2));&lt;/PRE&gt;
&lt;P&gt;Or create your own picture format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 07:35:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501042#M133541</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-10-03T07:35:19Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to convert character Datetime into 01MMMyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501078#M133556</link>
      <description>&lt;P&gt;Hi everyone.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for the confusion.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Let me explain in detailed.&lt;/P&gt;&lt;P&gt;Initially, I have a data step that has a hash object statement in it to do table lookup. However, one of the source columns has been changed, which it provides the month and year in character format. So for now, I have to pick another column which stores the datetime in character type.&lt;/P&gt;&lt;P&gt;The data looks like that:&lt;/P&gt;&lt;P&gt;1-May-2015 10:00:00&lt;/P&gt;&lt;P&gt;13-Jun-2015 01:30:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data first;
length lf_date $30 
infile DATALINES dsd missover;
input lf_date;
cards;
1/5/2015 10:00
31/5/2015 10:00
13/6/2015 1:30
18/12/2017 1:30
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In my data step, i previously had a where clause to filter out data that is not needed. Initially, i had this where clause:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;where put(input(cats('01',scan(file_source,1,'.')),date9.), yymmn6.) eq "&amp;amp;Period";&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the data in file_source looks like below:&lt;/P&gt;&lt;P&gt;Jan17.csv&lt;/P&gt;&lt;P&gt;Feb17.csv&lt;/P&gt;&lt;P&gt;The where clause above works perfectly as it will first scan and get the data before the 1st dot. Then, Concat 01,Jan17 tgt and format it with date9 in input statement which converts the data into numeric. Then, convert the value into yymmn6 which will produce the result like below:&lt;/P&gt;&lt;P&gt;201805&lt;/P&gt;&lt;P&gt;201603&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Variable Period is assigned before the starts of data step. Lets assume we hardcode Period=201805 in this case.&lt;/P&gt;&lt;P&gt;Notice the variable "Period" in the where clause. The value of Period is always in the format of 201805 or 201402 and etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Until recently, file_source column has been removed and all i can use is a column(lt_date) that has the value of below :&lt;/P&gt;&lt;P&gt;1-May-2015 10:00:00&lt;/P&gt;&lt;P&gt;13-Jun-2015 01:30:00&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have tried with all kind of possible combination of scan substr and etc to extract the data from the above format into 201805 format in a single where clause statement without having to create a new variable as a new variable will require a new datastep for the filtering(meaning the new variable cannot be used within the same datastep or else it will throw error "column not found in set table".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For now, I have below codes written which i think is not efficient as I have to create a new datastep to do the where clause filter:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;if lt_date ne '-' then do;

		removedtime=substr(scan(lt_date,-1,'-'),1,4);
		removedday=scan(lt_date,-2,'-');
		mthyr=put(input(cats('01',removedday,removedtime),date9.),yymmn6.);	
		output dm.ncp_load_tnbt_&amp;amp;period;
		end;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;as you all can see, mthyr is newly created in the if statement above. I cannot put statement below within the same "if" block.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;where mthyr = "&amp;amp;Period";&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hence, in my script, I have 2 datastep.&lt;/P&gt;&lt;P&gt;1st data step:&lt;/P&gt;&lt;P&gt;- read from source table, and include hash object lookup statement.&lt;/P&gt;&lt;P&gt;- Include IF statement above to assign into new column called newyr&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2nd data step:&lt;/P&gt;&lt;P&gt;- read from 1st data step&lt;/P&gt;&lt;P&gt;- apply where clause to filter the period.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i want to do is to eliminate the 2nd data step, and perform everything within the first data step. However, up to this point, i cannot think of a better way to do so. If anyone has a better solution, I would be more than happier to know.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 11:02:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501078#M133556</guid>
      <dc:creator>WorkingMan</dc:creator>
      <dc:date>2018-10-03T11:02:47Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to convert character Datetime into 01MMMyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501085#M133559</link>
      <description>&lt;P&gt;At the end of the first data step, create a new variable with the correctly formatted date, then add the following code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if newvar = "&amp;amp;period.";
drop newvar;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 03 Oct 2018 11:11:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501085#M133559</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-10-03T11:11:39Z</dc:date>
    </item>
    <item>
      <title>Re: Need help to convert character Datetime into 01MMMyy</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501200#M133606</link>
      <description>&lt;P&gt;Anytime you want to compare dates, times or datetimes create a SAS date, time or datetime valued numeric. You will save yourself a LOT of time and headache in the long run.&lt;/P&gt;</description>
      <pubDate>Wed, 03 Oct 2018 16:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-to-convert-character-Datetime-into-01MMMyy/m-p/501200#M133606</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-10-03T16:14:02Z</dc:date>
    </item>
  </channel>
</rss>

