<?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: Formats in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524311#M142574</link>
    <description>&lt;P&gt;&amp;nbsp;Since you have datetime variables initially, they have to be converted to date variables for the format to correctly be applied.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
Set Have;

Array X _Numeric_;

Do Over X;
X = Datepart(X);&lt;BR /&gt;End;&lt;BR /&gt;&lt;BR /&gt;Attrib _Numeric_ Format = Date9.;&lt;BR /&gt;/* If you have other numeric variables in your dataset which you do not want to apply the format to, then specify each variable you want the format applied to. */

Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 03 Jan 2019 16:22:11 GMT</pubDate>
    <dc:creator>jdwaterman91</dc:creator>
    <dc:date>2019-01-03T16:22:11Z</dc:date>
    <item>
      <title>Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524258#M142543</link>
      <description>&lt;P&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt; &lt;STRONG&gt;IMPORT&lt;/STRONG&gt; DBMS=ACCESSCS DATATABLE='RVDEC'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 16:04:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524258#M142543</guid>
      <dc:creator>JibJam221</dc:creator>
      <dc:date>2019-01-03T16:04:11Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524272#M142547</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can use the vformat function to check the formats of the elements in an array.&lt;/P&gt;
&lt;P&gt;Also, you cannot change the format of a dataset column on the fly. You have to create a new&lt;/P&gt;
&lt;P&gt;column and drop the old one.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data mpart;
    format  BDAY REcDate ReTDate datetime.;
    BDAY=datetime();
    RecDate=datetime();
    RetDate=datetime();
    x=1;
run;

data _NULL_;
    set work.mpart;
    array fixed _NUMERIC_;

    call execute('data want; set work.mpart;');

    do over fixed;
        if vformat(fixed)=:"DATETIME" then do;
            varname=vname(fixed);
            call execute(cat('drop ',strip(varname),';'));
            call execute(cat('format N_',strip(varname),' date9.;'));
            call execute(cats('N_',varname,'=datepart(',varname,');'));
        end;
    end;

    call execute('run;');

    stop;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Jan 2019 14:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524272#M142547</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-01-03T14:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524277#M142550</link>
      <description>Hi! Thanks so much for this,&lt;BR /&gt;I receive an error stating File Work.DROP.DATA doesn't exist. However, cannot localize where this error is coming from. Do you have any ideas?</description>
      <pubDate>Thu, 03 Jan 2019 14:56:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524277#M142550</guid>
      <dc:creator>JibJam221</dc:creator>
      <dc:date>2019-01-03T14:56:47Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524279#M142552</link>
      <description>From the error message, i would say that you forgot the semi-colon after  'set work.mpart' in the first call execute. If not, post the complet log to help us diagnose the problem.</description>
      <pubDate>Thu, 03 Jan 2019 15:01:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524279#M142552</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-01-03T15:01:48Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524281#M142554</link>
      <description>&lt;P&gt;You can use an attrib statement in a data step.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Attrib BDAY REcDate ReTDate Y201 Y22 Y716 Y133 Y876 Y7623 Y8613 Format = Date9.;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Thu, 03 Jan 2019 15:10:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524281#M142554</guid>
      <dc:creator>jdwaterman91</dc:creator>
      <dc:date>2019-01-03T15:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524285#M142556</link>
      <description>hi! When using this, the columns listed present '******' instead of the actual date. any ideas on how to get around this issue?</description>
      <pubDate>Thu, 03 Jan 2019 15:17:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524285#M142556</guid>
      <dc:creator>JibJam221</dc:creator>
      <dc:date>2019-01-03T15:17:40Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524289#M142559</link>
      <description>&lt;P&gt;Here is the log when using the do loop method&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 15:20:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524289#M142559</guid>
      <dc:creator>JibJam221</dc:creator>
      <dc:date>2019-01-03T15:20:09Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524291#M142560</link>
      <description>&lt;P&gt;I would suggest making your columns wider. I'm guessing that it is displaying that way in your dataset due to the columns not being wide enough.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 15:23:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524291#M142560</guid>
      <dc:creator>jdwaterman91</dc:creator>
      <dc:date>2019-01-03T15:23:29Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524292#M142561</link>
      <description>Hi again, after looking it up, enterprise 7.1 masks these when ATTRIB is used. However, when using base sas 9.2, I receive and error stating: ERROR: There was a problem with the format so BEST. was used.&lt;BR /&gt;&lt;BR /&gt;As a result, the date variable is not displayed. Any suggestions?&lt;BR /&gt;</description>
      <pubDate>Thu, 03 Jan 2019 15:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524292#M142561</guid>
      <dc:creator>JibJam221</dc:creator>
      <dc:date>2019-01-03T15:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524296#M142563</link>
      <description>&lt;P&gt;Please post the log as text as some contributors cannot or won't open attached documents.&lt;BR /&gt;It would be useful to have the complete log indicating which code has been executed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For instance, here is the log i obtain :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;696
697  data _NULL_;
698      set work.mpart;
699      array fixed _NUMERIC_;
700
701      call execute('data want; set work.mpart;');
702
703      do over fixed;
704          if vformat(fixed)=:"DATETIME" then do;
705              varname=vname(fixed);
706              call execute(cat('drop ',strip(varname),';'));
707              call execute(cat('format N_',strip(varname),' date9.;'));
708              call execute(cats('N_',varname,'=datepart(',varname,');'));
709          end;
710      end;
711
712      call execute('run;');
713
714      stop;
715  run;

NOTE: There were 1 observations read from the data set WORK.MPART.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


NOTE: CALL EXECUTE generated line.
1   + data want; set work.mpart;
2   + drop BDAY;
3   + format N_BDAY date9.;
4   + N_BDAY=datepart(BDAY);
5   + drop REcDate;
6   + format N_REcDate date9.;
7   + N_REcDate=datepart(REcDate);
8   + drop ReTDate;
9   + format N_ReTDate date9.;
10  + N_ReTDate=datepart(ReTDate);
11  + run;

NOTE: There were 1 observations read from the data set WORK.MPART.
NOTE: The data set WORK.WANT has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Jan 2019 15:33:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524296#M142563</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2019-01-03T15:33:37Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524298#M142564</link>
      <description>&lt;P&gt;hi! After running it in Base SAS (as opposed to enterprise guide) I was able to get a successful output!&lt;/P&gt;&lt;P&gt;Thank you so much.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Jan 2019 15:39:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524298#M142564</guid>
      <dc:creator>JibJam221</dc:creator>
      <dc:date>2019-01-03T15:39:21Z</dc:date>
    </item>
    <item>
      <title>Re: Formats</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524311#M142574</link>
      <description>&lt;P&gt;&amp;nbsp;Since you have datetime variables initially, they have to be converted to date variables for the format to correctly be applied.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Want;
Set Have;

Array X _Numeric_;

Do Over X;
X = Datepart(X);&lt;BR /&gt;End;&lt;BR /&gt;&lt;BR /&gt;Attrib _Numeric_ Format = Date9.;&lt;BR /&gt;/* If you have other numeric variables in your dataset which you do not want to apply the format to, then specify each variable you want the format applied to. */

Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Jan 2019 16:22:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Formats/m-p/524311#M142574</guid>
      <dc:creator>jdwaterman91</dc:creator>
      <dc:date>2019-01-03T16:22:11Z</dc:date>
    </item>
  </channel>
</rss>

