<?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: Converting Character to Date (Number) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139779#M296325</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try below (untested) code. If it still doesn't work then tell us what's in the SAS log.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data WANT;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; set Data;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; M1=input(InterestFrequency,best.);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; M2=input(MaturityDate,date.);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; M3=input(FirstCpnDt,date.);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; attrib m2 m3 format=date9.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 10 Sep 2014 22:00:10 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2014-09-10T22:00:10Z</dc:date>
    <item>
      <title>Converting Character to Date (Number)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139778#M296324</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have the attached output also shown below. This already exists in SAS, so my objective is not to import the .csv file into SAS; the .csv file is just attached for your convenience. The variables are all text/character variables and I am trying to convert them into numeric using the code below, however all that I get are numeric blanks ie ( . ).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Could someone please provide some insight? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data WANT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set Data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; M1=input(InterestFrequency,3.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; M2=input(MaturityDate,ddmmyy8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; M3=input(FirstCpnDt,ddmmyy8.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;**********************************************************&lt;/P&gt;&lt;P&gt;**********************************************************&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SAS DATASET&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;InterestFrequency&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MaturityDate&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FirstCpnDt&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15May2041&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 15Nov2011&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2014 21:54:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139778#M296324</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2014-09-10T21:54:20Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Date (Number)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139779#M296325</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try below (untested) code. If it still doesn't work then tell us what's in the SAS log.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;data WANT;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; set Data;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; M1=input(InterestFrequency,best.);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; M2=input(MaturityDate,date.);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp;&amp;nbsp; M3=input(FirstCpnDt,date.);&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&amp;nbsp; attrib m2 m3 format=date9.;&lt;/P&gt;&lt;P style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2014 22:00:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139779#M296325</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2014-09-10T22:00:10Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Date (Number)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139780#M296326</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try this.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data WANT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; set Data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; M1=input(InterestFrequency,8.);&lt;/P&gt;&lt;P&gt;&amp;nbsp; M2=input(MaturityDate,date9.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; M3=input(FirstCpnDt,date9.);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2014 22:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139780#M296326</guid>
      <dc:creator>stat_sas</dc:creator>
      <dc:date>2014-09-10T22:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Date (Number)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139781#M296327</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Patrick,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It didn't work; I am still getting blanks. Below is th elog.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;4736&amp;nbsp; data WANT;&lt;BR /&gt;4737&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set Data;&lt;BR /&gt;4738&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M1=input(InterestFrequency,best.);&lt;BR /&gt;4739&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M2=input(MaturityDate,date.);&lt;BR /&gt;4740&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; M3=input(FirstCpnDt,date.);&lt;BR /&gt;4741&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; attrib m2 m3 format=date9.;&lt;BR /&gt;4742&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;NOTE: There were 1 observations read from the data set WORK.DATA.&lt;BR /&gt;NOTE: The data set WORK.WANT has 1 observations and 6 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.01 seconds&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2014 22:09:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139781#M296327</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2014-09-10T22:09:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Date (Number)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139782#M296328</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This didn't work either; I am still getting blanks. The log is similar to the one I responded with to Patrick. I have three new variables forming, but all show up with blank (numeric) values (ie ( . ) ).&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2014 22:12:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139782#M296328</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2014-09-10T22:12:52Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Date (Number)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139783#M296329</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How did you create the set DATA? If you used proc import it may have read the date and created SAS date variables that being displayed using Date format and all you really need is to change the format associated to mmddyy8.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Run proc contents on the set data and show the result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2014 23:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139783#M296329</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-09-10T23:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Date (Number)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139784#M296330</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Could it be because the data in the file is formatted with DATE9 format instead of MMDDYY?&lt;/P&gt;&lt;P&gt;Do not look at the file with Excel as it will transform it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;RULE:&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ----+----1----+----2----+----3----+----4----+----5----+----6----&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; "InterestFrequency","MaturityDate","FirstCpnDt" 47&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2,15MAY2041,15NOV2011 21&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 10 Sep 2014 23:24:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139784#M296330</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2014-09-10T23:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: Converting Character to Date (Number)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139785#M296331</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Tom,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I can't thank you enough for your continued engagement. Below is the code that leads to the leads to the Data dataset mentioned above; in the code below the test2 dataset is the same as the Data dataset mentioned above. Are you saying that I should bring in ValuationDate and MaturityDate from the .csv file using an MMDDYY informat?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also, relating to your question on my other posting ("Not sure why this is not working"); this is best explained in the last data step below (data test3), which is a (cleaner) variation of the code I have in the other posting. I am trying to define arrays of different lengths depending on whether the InterestFrequency variable assumes a value of 2 or 12; InterestFrequency represents the frequency of the coupon payments on a bond, so if the bond pays interest semiannually (ie InterestFrequency=2) it will have different cashflows (represented by the array) from a bond that pays interest monthly (and hence, has a different array associated with it, whereby InterestFrequency=12). As you can see, my entire "data test3" datastep hinges on my being able to convert InterestFrequency, MaturityDate, and ValuationDate into numeric variables so that I can get the datastep to run.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hope this clarifies matters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data WORK.NCDebt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile '/fmacdata/utility/fin/KBenchmarks/SAS Data/NCDebt_1.csv' dsd lrecl=40000 firstobs=3;&lt;BR /&gt;informat ValuationDate yymmdd.;&lt;BR /&gt;informat MaturityDate mmddyy10.;&lt;BR /&gt;informat InterestFrequency 5.;&lt;BR /&gt;informat AccruedDayCount $10.;&lt;BR /&gt;format ValuationDate date9.&amp;nbsp; MaturityDate date9.;&lt;BR /&gt;input ValuationDate MaturityDate InterestFrequency AccruedDayCount $;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc transpose data=Ncdebt&lt;BR /&gt;&amp;nbsp; out=Ncdebt2;&lt;BR /&gt;&amp;nbsp; var ValuationDate MaturityDate InterestFrequency AccruedDayCount;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data Ncdebt3;&lt;BR /&gt;&amp;nbsp; set Ncdebt2(rename=(_NAME_=Var1));&lt;BR /&gt;&amp;nbsp; keep Var1 COL1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select COL1&lt;BR /&gt;&amp;nbsp; into: ValuationDate&lt;BR /&gt;&amp;nbsp; from Ncdebt3&lt;BR /&gt;&amp;nbsp; where Var1='ValuationDate';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;BR /&gt;&amp;nbsp; select COL1&lt;BR /&gt;&amp;nbsp; into: MaturityDate&lt;BR /&gt;&amp;nbsp; from Ncdebt3&lt;BR /&gt;&amp;nbsp; where Var1='MaturityDate';&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%let Result=%sysevalf("&amp;amp;MaturityDate"d-"&amp;amp;ValuationDate"d);&lt;BR /&gt;%put &amp;amp;Result;&lt;/P&gt;&lt;P&gt;proc transpose data=Ncdebt3&lt;BR /&gt;&amp;nbsp;&amp;nbsp; out=test;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; var var1 COL1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; id var1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test2;&lt;BR /&gt;&amp;nbsp; set test (firstobs=2);&lt;BR /&gt;&amp;nbsp; keep MaturityDate ValuationDate InterestFrequency;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data Test3;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; set Test2;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; if InterestFrequency='2' then do; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count1=(intck('semiyear',ValuationDate,MaturityDate)+1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let arrelements=count1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array dt{&amp;amp;arrelements} dt1-dt&amp;amp;arrelements;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; else if InterestFrequency='12' then do; &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; count1=(intck('month',ValuationDate,MaturityDate)+1);&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let arrelements=count1;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; array date{&amp;amp;arrelements} date1-date&amp;amp;arrelements;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; end;&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 01:02:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-Character-to-Date-Number/m-p/139785#M296331</guid>
      <dc:creator>maroulator</dc:creator>
      <dc:date>2014-09-11T01:02:06Z</dc:date>
    </item>
  </channel>
</rss>

