<?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 of Best 12. to sas time format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378454#M90940</link>
    <description>&lt;P&gt;Sorry, but I don't know what a sas time character is. &amp;nbsp;Date and time variables are saved as numeric variables. &amp;nbsp;They can be displayed with a myriad of formats that do not change the underlying numeric values. &amp;nbsp;Now it is possible to create character variables that have values that we would interpret as times or dates, but I don't think that is what you are asking about. &amp;nbsp;Formats provide rules for mapping the values of numeric (in this case) but also character variables to formatted values, which are character strings that can be displayed in SAS output. &amp;nbsp;You can specify a format for one step, and change it for the next step. &amp;nbsp;I was working with a date/time variable the other day. Sometimes I displayed it using a date time format. &amp;nbsp;Other times, that took too much space and it wasn't important for my purpose (checking my code development) so I removed the format and had it print like an ordinary number. &amp;nbsp;Summary: variables have values, formats display the values in varying ways, and formats do not change the underlying values.&lt;/P&gt;</description>
    <pubDate>Sat, 22 Jul 2017 18:07:32 GMT</pubDate>
    <dc:creator>WarrenKuhfeld</dc:creator>
    <dc:date>2017-07-22T18:07:32Z</dc:date>
    <item>
      <title>Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378442#M90931</link>
      <description>&lt;P&gt;Sas time format beats me. I dont know why it's so complicated. variable STAPERS is&amp;nbsp;YYMMDDN8. format, &amp;nbsp;yymm became best12. How can i convert it to sas time format without changing its style. thanks&amp;amp; regards.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;mm=month(STATPERS);
yy=year(STATPERS);
/*format STATPERS yymmn6.;*/
if mm in (1,2,3) then yymm=yy*100+03;
if mm in (4,5,6) then yymm=yy*100+06;
if mm in (7,8,9) then yymm=yy*100+09;
if mm in (10,11,12) then yymm=yy*100+12;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Jul 2017 16:47:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378442#M90931</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-22T16:47:17Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378444#M90932</link>
      <description>&lt;P&gt;Use a FORMAT statement to assign formats&amp;nbsp;to variables. &amp;nbsp;There is nothing complicated about it. &amp;nbsp;If you run proc contents and don't like a format that you see, change it in the next proc or data step. &amp;nbsp;This next example, as silly as it is, illustrates.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc print data=sashelp.class;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp;format age mmddyy8. height 12.6 weight hex16.;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It only changes formats for the print step. &amp;nbsp;Use a format statement in a DATA step to change the format in the data set.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 16:56:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378444#M90932</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-07-22T16:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378446#M90934</link>
      <description>&lt;P&gt;But after I use format, it was changed &amp;nbsp;to the number like 251109 &amp;nbsp;which I can't realize. thank you&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 17:13:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378446#M90934</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-22T17:13:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378447#M90935</link>
      <description>&lt;P&gt;Formats do not change numbers. &amp;nbsp;They change how numbers are displayed. &amp;nbsp;Try this. &amp;nbsp;The numbers remain 1 to 10 no matter how they are formatted.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
   do x = 1 to 10;
      y = x;
      z = x;
      output;
      end;
format x mmddyy8. y date7. z 12.4;
run;

proc print; run;

data y;
   set x;
   format x y z; /* clear formats */
run;
proc print; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Jul 2017 17:24:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378447#M90935</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-07-22T17:24:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378451#M90937</link>
      <description>&lt;P&gt;OK, I get your answer. But when I use the function like&amp;nbsp;intnx, why should i change the numeric character to sas time character? Thank you&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 17:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378451#M90937</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-22T17:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378454#M90940</link>
      <description>&lt;P&gt;Sorry, but I don't know what a sas time character is. &amp;nbsp;Date and time variables are saved as numeric variables. &amp;nbsp;They can be displayed with a myriad of formats that do not change the underlying numeric values. &amp;nbsp;Now it is possible to create character variables that have values that we would interpret as times or dates, but I don't think that is what you are asking about. &amp;nbsp;Formats provide rules for mapping the values of numeric (in this case) but also character variables to formatted values, which are character strings that can be displayed in SAS output. &amp;nbsp;You can specify a format for one step, and change it for the next step. &amp;nbsp;I was working with a date/time variable the other day. Sometimes I displayed it using a date time format. &amp;nbsp;Other times, that took too much space and it wasn't important for my purpose (checking my code development) so I removed the format and had it print like an ordinary number. &amp;nbsp;Summary: variables have values, formats display the values in varying ways, and formats do not change the underlying values.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 18:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378454#M90940</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-07-22T18:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378458#M90944</link>
      <description>&lt;P&gt;I am a new user of sas, and I learned from a book which had said 'the sas variable includes character variable and numeric variable", so I make the mistake. Thank you for letting me know the underlying rules of sas.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 18:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378458#M90944</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-22T18:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378459#M90945</link>
      <description>&lt;P&gt;Right. &amp;nbsp;Variables can be character or numeric. &amp;nbsp;Date/time variables are numeric. &amp;nbsp;Formats display underlying values as character strings using a particular set of rules. &amp;nbsp;There are probably hundreds of formats. &amp;nbsp;Many apply to dates and times. &amp;nbsp;Plus, you can write your own formats. &amp;nbsp;For example you could write a format that displays 1 as 'Disagree', 2 as 'Not Sure', and 3 as 'Agree' (or any one of an infinite number of other possibilities).&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 18:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378459#M90945</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-07-22T18:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378461#M90947</link>
      <description>&lt;P&gt;It's amazing. May I ask you another question? I got a code as following:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_base;
input company$ _date:$6. profit;
date = input(_date !! '01',yymmdd8.);
format date yymmn6.;
drop _date;
datalines;
a 199701 5
a 199606 9
b 201404 6
f 200004 78
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;My question is why the coder didn't use a simplier code? I ran the both and found both result are same.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have_base;
input company$ date yymmn6. profit;
format date yymmn6.;
datalines;
a 199701 5
a 199606 9
b 201404 6
f 200004 78
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 22 Jul 2017 19:17:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378461#M90947</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-22T19:17:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378462#M90948</link>
      <description>&lt;P&gt;I don't know. &amp;nbsp;I wish I could say that I always wrote the simplest possble code but even after 38 years of experience with SAS, I don't always think of the best way to do things. &amp;nbsp;Probably the person who wrote it did not know the best way to handle that particular date issue. &amp;nbsp;It is good that you tried it two ways and learned something new about dates. &amp;nbsp;I don't think I have ever encountered that particular form of date input before. &amp;nbsp;Cheers.&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 20:02:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378462#M90948</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2017-07-22T20:02:54Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378470#M90953</link>
      <description>&lt;P&gt;You heading mentions TIME formats, but your example clearly is talking about DATE values, not TIME values.&amp;nbsp;If your variable is actually a DATE&amp;nbsp;value then its value will have the number of days since beginning of 1960. &amp;nbsp;If it was a TIME value then it would have the number of seconds since midnight. &amp;nbsp;It it was a DATETIME value then it would have the number of seconds since 1960.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can attach a different format to a variable to have it print in many ways. &amp;nbsp;Try this little exmple to see.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  x=date();
  length format $12 str $30 ;
  do format='comma12.','date9.','yymmdd10.','yymm7.','yyq6.','year.','month.','qtr.';
    str=putn(x,format);
    put format @15 str ;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;What is your actual question? What does your input data look like and what data to you want out?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 22 Jul 2017 22:16:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378470#M90953</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-22T22:16:33Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378488#M90965</link>
      <description>&lt;P&gt;Hi Tom, sorry I confused time character with date character. &amp;nbsp;My input data is date, and my question is very simple. I just want the result after caculation is yymmn6. format. The process likes this&amp;nbsp;&lt;/P&gt;&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;yymm&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;yy&lt;SPAN class="token operator"&gt;*&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;100&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;+&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;03&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want yymm to be yymmn6.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jul 2017 03:24:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378488#M90965</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-23T03:24:23Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378490#M90967</link>
      <description>&lt;P&gt;I format yymm, but I can't realize them. It's all right. I think I can change them when I need to use and change them back when I need to output them.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jul 2017 03:37:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378490#M90967</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-23T03:37:43Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378502#M90970</link>
      <description>&lt;P&gt;Jag, Thanks again. After I have tried for several time, I really understand your said.&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jul 2017 07:14:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378502#M90970</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-23T07:14:01Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378531#M90987</link>
      <description>&lt;P&gt;You can get dates to appear in YYYYMM format by using the YYMMN6. format.&lt;/P&gt;
&lt;P&gt;If you want the values stored as strings then just use the PUT() function. &amp;nbsp;If you want the value stored as a number you an either use INPUT() function on the string generated by the PUT() function or in this case just &amp;nbsp;use the YEAR() and MONTH() functions and you arithmetic expression.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;datestr= put(date,yymmn6.);
date_like_num = input(put(date,yymmn6.),6.);
date_like_num = 100*year(date)+month(date) ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;From the example code you posted it looks like you actually want to convert to the last month of the quarter instead. &amp;nbsp;You can use the INTNX() function to do that for you. &amp;nbsp;So if you want Jan, Feb, and Mar to appear as 03 you could find the last day of the quarter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;newdate = intnx('qtr',date,0,'e');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could then convert NEWDATE to your YYYYMM string or YYY,YMM number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Jul 2017 13:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378531#M90987</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-07-23T13:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: Convert of Best 12. to sas time format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378614#M91037</link>
      <description>&lt;P&gt;Tom, Thank you ver much.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Jul 2017 09:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-of-Best-12-to-sas-time-format/m-p/378614#M91037</guid>
      <dc:creator>lixuan</dc:creator>
      <dc:date>2017-07-24T09:16:14Z</dc:date>
    </item>
  </channel>
</rss>

