<?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 Change all the date variable in MMDDYY10. format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603147#M174735</link>
    <description>&lt;P&gt;Dear Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I import the data into SAS from SQL Server (then analyzed) and Exported the dataset to Excel.&lt;/P&gt;&lt;P&gt;The date variable in the format of DATETIME22.3. (10NOV1947:00:00:000)&lt;/P&gt;&lt;P&gt;I know the way to convert for one/two variables. but my dataset has 50 more date variables.&lt;/P&gt;&lt;P&gt;I want to format all variables in MMDDYY10. at one shot.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly suggest code to solve the date format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 11 Nov 2019 11:47:49 GMT</pubDate>
    <dc:creator>Sathish_jammy</dc:creator>
    <dc:date>2019-11-11T11:47:49Z</dc:date>
    <item>
      <title>Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603147#M174735</link>
      <description>&lt;P&gt;Dear Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I import the data into SAS from SQL Server (then analyzed) and Exported the dataset to Excel.&lt;/P&gt;&lt;P&gt;The date variable in the format of DATETIME22.3. (10NOV1947:00:00:000)&lt;/P&gt;&lt;P&gt;I know the way to convert for one/two variables. but my dataset has 50 more date variables.&lt;/P&gt;&lt;P&gt;I want to format all variables in MMDDYY10. at one shot.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly suggest code to solve the date format.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 11:47:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603147#M174735</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-11-11T11:47:49Z</dc:date>
    </item>
    <item>
      <title>Re: Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603148#M174736</link>
      <description>&lt;P&gt;is there some common patter that identifies the 50 variables? Like a common prefix/suffix?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 11:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603148#M174736</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-11-11T11:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603153#M174738</link>
      <description>&lt;P&gt;For five variables the suffix is like _date, the remaining date variable suffix is like _DT.&lt;/P&gt;&lt;P&gt;It'll be fine enough for me to convert only&amp;nbsp; (suffix)_DT variables.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 12:10:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603153#M174738</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2019-11-11T12:10:29Z</dc:date>
    </item>
    <item>
      <title>Re: Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603169#M174745</link>
      <description>&lt;P&gt;Had the common naming been something like DATE1-DATE50, or even if all the variables had the same starting letters (example: they all begin with the letters DT_), this is simple; all you need is one FORMAT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If they all end with _DATE or end with _DT (why are they named this way, anyway? is that how they come from the database?), then you'd probably need some sort of SQL solution, use SQL to create a macro variable that contains all fifty variable names. Sounds easier and more beneficial in the long run to go back and correct the naming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    select distinct name into :names from dictionary.columns where memname="YOURDATASETNAME"
    and libname="YOURLIBRARYNAME" and (scan(name,-1,'_')='DT' or scan(name,-1,'_')='DATE');
quit;

data new;
    set yourlibraryname.yourdatasetname;
    format &amp;amp;names mmddyy10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 12:59:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603169#M174745</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-11T12:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603270#M174797</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215282"&gt;@Sathish_jammy&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;The issue is two-pronged:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Your values are datetimes but you want to format them as dates. The only canned format I know of that does that is E8601DN. However, it displays datetimes as YYYY-MM-DD (which to me is the only sane way to format dates); yet you want it as MM/DD/YYYY. If you okay with YYYY-MM-DD instead, then E8601DN. can be used directly in reformatting code. If not, you'll have to create a format formatting date times as MM/DD/YYYY via creating a function with proc FCMP and using it to compile a special format.&lt;/LI&gt;
&lt;LI&gt;Whatever decision is made above, use SQL to list the variables whose format begins wiht "DATETIME" and compose the corresponding ALTER statement.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;First, suppose you're okay with YYYY-MM-DD (HAVE is just a test data set with datetime variables formatted as DATETIME22.3 and some other unrelated variables):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                                                                                                             
  dt = "10NOV2019:00:00:00"dt ;                                                                                                         
  date_a = dt + 123456789 ;                                                                                                             
  b_date = date_a + 123456789 ;                                                                                                         
  format dt date_a b_date datetime22.3 ;                                                                                                
  retain otherc "otherc" othern1 111 othern2 222 ;                                                                                      
run ;                                                                                                                                   
                                                                                                                                        
proc sql noprint ;                                                                                                                      
  select catx (" ", name, "format=e8601dn10.") into :dtv separated by ","                                                               
  from   dictionary.columns                                                                                                             
  where  libname = "WORK" and memname = "HAVE" and format eqt "DATETIME"                                                                
  order  varnum                                                                                                                         
  ;                                                                                                                                     
  alter table have modify &amp;amp;dtv ;                                                                                                        
quit ;                
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;If you run this code and look at HAVE, you'll see that the datetime variables are displayed as YYYY-MM-DD.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now suppose that you still want the datetimes to be displayed as MM/DD/YYYY. In this case, you need to create a special format and then use it in SQL instead of E8601DN. This is one way to do it:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib = work.f.f ;                                                                                                           
  function dtfmt (dt) $ ;                                                                                                               
  return (put (datepart (dt), mmddyy10.)) ;                                                                                             
  endsub ;                                                                                                                              
quit ;                                                                                                                                  
                                                                                                                                        
option cmplib = work.f ;                                                                                                                
                                                                                                                                        
proc format ;                                                                                                                           
  value dtfmt (default=10) other=[dtfmt()] ;                                                                                            
run ;                                                                                                                                   
                                                                                                                                        
proc sql noprint ;                                                                                                                      
  select catx (" ", name, "format=dtfmt.") into :dtv separated by ","                                                                   
  from   dictionary.columns                                                                                                             
  where  libname = "WORK" and memname = "HAVE" and format eqt "DATETIME"                                                                
  order  varnum                                                                                                                         
  ;                                                                                                                                     
  alter table have modify &amp;amp;dtv ;                                                                                                        
quit ;                           
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now if you look at HAVE, you'll see that the datetime variables appear formatted as MM/DD/YYYY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000FF"&gt;EDIT:&lt;/FONT&gt; As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;has pointed out, you don't have to create the DTFMT. format using proc FCMP; you can create a picture format instead, for example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format ;                                                            
  picture dtfmt (default=10) low-high = '%0m/01/%Y' (datatype=datetime) ;
run ;                                                                    
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 17:05:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603270#M174797</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-11T17:05:36Z</dc:date>
    </item>
    <item>
      <title>Re: Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603274#M174799</link>
      <description>&lt;P&gt;Why would you use FCMP instead of a PICTURE format?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 16:31:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603274#M174799</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-11T16:31:55Z</dc:date>
    </item>
    <item>
      <title>Re: Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603276#M174800</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Two points:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When datetime/timestamp variables come from MS SQL server, SAS auto-assigns a DATETIMEw.d format to them. Hence, there's no need to rely on variable names to determine which ones need to be reformatted, as it's enough to find out which ones have formats starting with "DATETIME".&lt;/LI&gt;
&lt;LI&gt;Reassigning the formats the way you suggest will rewrite a potentially large data set. It's unnecessary since to reassign a format, it suffices to modify only the data set's descriptor via either proc DATASETS or proc SQL without touching the actual data.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 16:35:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603276#M174800</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-11T16:35:44Z</dc:date>
    </item>
    <item>
      <title>Re: Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603279#M174801</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;: I have no clue. It just occurred to me to do it this way, and it didn't occur to me to use a picture format ;). Thanks for the reminder.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 16:39:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603279#M174801</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-11T16:39:22Z</dc:date>
    </item>
    <item>
      <title>Re: Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603293#M174803</link>
      <description>&lt;P&gt;Do you want to convert the values from number of seconds (DATETIME values) to number of days (DATE values)? Or are you just looking to a way to display the datetime values with only the datepart?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you need to do this for ALL of the datetime values in your dataset? Or just some of them? If just some of them how can you identify which ones need to be changed?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Are you looking for a solution in SAS or in the exported Excel file?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that Excel, like SQL Server, does not really have a DATE data type.&amp;nbsp; Only the DATETIME data type that you currently have.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you really need the values to display in the confusing month,day,year order?&amp;nbsp; Why not just use the DTDATE format to display just the datepart of the datetime values?&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 17:48:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603293#M174803</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-11T17:48:24Z</dc:date>
    </item>
    <item>
      <title>Re: Change all the date variable in MMDDYY10. format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603295#M174805</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/21262"&gt;@hashman&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Two points:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;When datetime/timestamp variables come from MS SQL server, SAS auto-assigns a DATETIMEw.d format to them. Hence, there's no need to rely on variable names to determine which ones need to be reformatted, as it's enough to find out which ones have formats starting with "DATETIME".&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Unless you only want the ones with variable names ending in DT and DATE, and not other similarly formatted variables whose name doesn't end with those strings. But neither your way nor my way might be completely definitive, depending on which exact 50 variables are needed.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;
&lt;BLOCKQUOTE&gt;Reassigning the formats the way you suggest will rewrite a potentially large data set. It's unnecessary since to reassign a format, it suffices to modify only the data set's descriptor via either proc DATASETS or proc SQL without touching the actual data.&lt;/BLOCKQUOTE&gt;
&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes, PROC DATASETS would be a better approach.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Nov 2019 18:09:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Change-all-the-date-variable-in-MMDDYY10-format/m-p/603295#M174805</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-11-11T18:09:53Z</dc:date>
    </item>
  </channel>
</rss>

