<?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 to a Date in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279403#M56321</link>
    <description>&lt;P&gt;Hi itshere,&lt;/P&gt;&lt;P&gt;I have make a simple try below assuming different type of car purchased per month. If you could provide more information about uniqueness, I may try to refine it further.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
format date datetime21.;
input  type $ date datetime21.  ;
cards;
a 01OCT2015:15:22:22
b 3OCT2015:15:22:22
a 11OCT2015:15:22:22
b 13OCT2015:15:22:22
c 11OCT2015:15:22:22
b 30OCT2015:15:22:22
a 01NOV2015:15:22:22
a 02NOV2015:15:22:22
b 03NOV2015:15:22:22
a 01MAR2015:15:22:22
b 02MAR2015:15:22:22
c 03MAR2015:15:22:22
;
run;

data test2;
	set test1;
	month=put(datepart(date),worddatx9.);
run;

proc sql;
   create table test3 as
        select month, type,count(type) as num_of_car_per_month
          from test2
             group by month, type
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jun 2016 15:48:52 GMT</pubDate>
    <dc:creator>DeepakSwain</dc:creator>
    <dc:date>2016-06-22T15:48:52Z</dc:date>
    <item>
      <title>Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279356#M56293</link>
      <description>&lt;P&gt;2 part questions, PLEASE HELP!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I currently have&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;01OCT2015:15:22:22 in my column.. I want to add a new column that will just say OCTOBER&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Im using SAS PROC SQL and need to creat another table..&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;So it would be rsubmit;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table test1.new as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;.......&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2)&lt;/P&gt;
&lt;P&gt;I have a column that says CARS and and MONTHS ( that will be from the above query)&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the times I need to count the number of cars purchased for each months.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and then i need another query that shows only the UNIQUE numbers of CARS for each months.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So one with total (with dups) and other time with just Unique ones?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PLEASE HELP. Also using proc sql and need to create another table.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 14:27:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279356#M56293</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-06-22T14:27:01Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279365#M56297</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1) Here's an example that you can execute&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    month=put(datepart("01OCT2015:15:22:22"dt),worddatx9.);
    put month=;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;- 01OCT2015:15:22:22 is a datetime. To convert it to a date you can use datepart function.&lt;BR /&gt;- worddatw9. is a format that displays the date's month.&lt;/P&gt;
&lt;P&gt;- put function creates a string based on the format applyed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2)&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
   create table want as
        select month
                 ,count(1) as nb_cars
                 ,count(distinct cars) as nb_distinct_cars
          from have
             group by month
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps !&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 14:49:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279365#M56297</guid>
      <dc:creator>majdi_ka</dc:creator>
      <dc:date>2016-06-22T14:49:36Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279370#M56302</link>
      <description>&lt;P&gt;For the first part.. you did&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;datepart&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;"01OCT2015:15:22:22"&lt;/SPAN&gt;dt&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but its the entire column thats like that so I would need to convert the entire column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also.. how do i leave that column and create a new one with the actual MONTH?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 14:56:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279370#M56302</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-06-22T14:56:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279379#M56304</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example that can help. the first data step is to simulate the data that you have. The second is to create the output that you wanted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
format date datetime21.;
input date datetime21. ;
cards;
01OCT2015:15:22:22
3OCT2015:15:22:22
01NOV2015:15:22:22
01MAR2015:15:22:22
01FEB2015:15:22:22
01SEP2015:15:22:22
01AUG2015:15:22:22
;
run;

data want;
	set have;
	month=put(datepart(date),worddatx9.);
run;&lt;/CODE&gt;&lt;/PRE&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;</description>
      <pubDate>Wed, 22 Jun 2016 15:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279379#M56304</guid>
      <dc:creator>majdi_ka</dc:creator>
      <dc:date>2016-06-22T15:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279384#M56307</link>
      <description>&lt;P&gt;I used the second query and put in the column name in the "date" &amp;nbsp;and it didnt work....&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how would i create a table rathe than overwrite the existing one?&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 15:18:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279384#M56307</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-06-22T15:18:33Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279387#M56309</link>
      <description>Can you please share your code ?</description>
      <pubDate>Wed, 22 Jun 2016 15:22:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279387#M56309</guid>
      <dc:creator>majdi_ka</dc:creator>
      <dc:date>2016-06-22T15:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279392#M56312</link>
      <description>NOTE: Variable start_time is uninitialized.&lt;BR /&gt;month=.&lt;BR /&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;      Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;      1 at 17:15&lt;BR /&gt;</description>
      <pubDate>Wed, 22 Jun 2016 15:29:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279392#M56312</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-06-22T15:29:17Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279394#M56313</link>
      <description>This is the log, the result of the execution of your code, and not the code. Can you the code you executed that you find in the editor ?</description>
      <pubDate>Wed, 22 Jun 2016 15:31:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279394#M56313</guid>
      <dc:creator>majdi_ka</dc:creator>
      <dc:date>2016-06-22T15:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279397#M56316</link>
      <description>rsubmit;&lt;BR /&gt;data test1.new&lt;BR /&gt;    month=put(datepart(start_time),worddatx9.);&lt;BR /&gt;    put month=;&lt;BR /&gt;run;</description>
      <pubDate>Wed, 22 Jun 2016 15:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279397#M56316</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-06-22T15:41:22Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279398#M56317</link>
      <description>you forgot the set statement with the table containing your variable start_time.</description>
      <pubDate>Wed, 22 Jun 2016 15:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279398#M56317</guid>
      <dc:creator>majdi_ka</dc:creator>
      <dc:date>2016-06-22T15:43:39Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279402#M56320</link>
      <description>but will it create a new column or overwrite the existing column?</description>
      <pubDate>Wed, 22 Jun 2016 15:48:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279402#M56320</guid>
      <dc:creator>itshere</dc:creator>
      <dc:date>2016-06-22T15:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Converting to a Date</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279403#M56321</link>
      <description>&lt;P&gt;Hi itshere,&lt;/P&gt;&lt;P&gt;I have make a simple try below assuming different type of car purchased per month. If you could provide more information about uniqueness, I may try to refine it further.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test1;
format date datetime21.;
input  type $ date datetime21.  ;
cards;
a 01OCT2015:15:22:22
b 3OCT2015:15:22:22
a 11OCT2015:15:22:22
b 13OCT2015:15:22:22
c 11OCT2015:15:22:22
b 30OCT2015:15:22:22
a 01NOV2015:15:22:22
a 02NOV2015:15:22:22
b 03NOV2015:15:22:22
a 01MAR2015:15:22:22
b 02MAR2015:15:22:22
c 03MAR2015:15:22:22
;
run;

data test2;
	set test1;
	month=put(datepart(date),worddatx9.);
run;

proc sql;
   create table test3 as
        select month, type,count(type) as num_of_car_per_month
          from test2
             group by month, type
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 15:48:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Converting-to-a-Date/m-p/279403#M56321</guid>
      <dc:creator>DeepakSwain</dc:creator>
      <dc:date>2016-06-22T15:48:52Z</dc:date>
    </item>
  </channel>
</rss>

