<?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: Changing formats based on the format? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Changing-formats-based-on-the-format/m-p/281976#M57244</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no such thing as datetime variable in SAS. There are only 2 types of variables in SAS: numeric and character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you check the type of variable stored within each dataset (using the dictionaries - sashelp.vcolumn, in this case)&lt;/P&gt;
&lt;P&gt;and act accordingly based on type of variable.&lt;/P&gt;</description>
    <pubDate>Mon, 04 Jul 2016 11:20:12 GMT</pubDate>
    <dc:creator>Loko</dc:creator>
    <dc:date>2016-07-04T11:20:12Z</dc:date>
    <item>
      <title>Changing formats based on the format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-formats-based-on-the-format/m-p/281974#M57243</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have several data sets that all contain the same variables. Problem is, one date variable is sometimes stored as a date variable, sometimes as a character variable. There is not apparend systematic to which is which and I dont want to check every data set (there are about 50).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have this code:&lt;/P&gt;&lt;P&gt;it works well, when the variable (published)&amp;nbsp;is a character variable, but when it is a datetime variable it just gives me missing.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro published(have);

%do i=1 %to 50;

DATA work.want
set &amp;amp;have._&amp;amp;i.;
  published_1 = input(published ,ANYDTDTE16.);
  format published_1 date9.;
RUN;

%end;
%mend published;

%published(have)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Any Idea how I could run this for all data sets?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(Btw: when published is stored as a date variables it is a datetime variable, and I only need the date.)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks a lot!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2016 10:21:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-formats-based-on-the-format/m-p/281974#M57243</guid>
      <dc:creator>myname</dc:creator>
      <dc:date>2016-07-04T10:21:15Z</dc:date>
    </item>
    <item>
      <title>Re: Changing formats based on the format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-formats-based-on-the-format/m-p/281976#M57244</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There is no such thing as datetime variable in SAS. There are only 2 types of variables in SAS: numeric and character.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you check the type of variable stored within each dataset (using the dictionaries - sashelp.vcolumn, in this case)&lt;/P&gt;
&lt;P&gt;and act accordingly based on type of variable.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2016 11:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-formats-based-on-the-format/m-p/281976#M57244</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-07-04T11:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: Changing formats based on the format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-formats-based-on-the-format/m-p/281985#M57247</link>
      <description>&lt;P&gt;Use conditional logic, untested. Not sure what VType returns or if this might throw an error due to mixing of types.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If vtype(published)='C' then published_i=input...;&lt;/P&gt;
&lt;P&gt;else published_i=datepart(published);&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2016 12:47:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-formats-based-on-the-format/m-p/281985#M57247</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-07-04T12:47:38Z</dc:date>
    </item>
    <item>
      <title>Re: Changing formats based on the format?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Changing-formats-based-on-the-format/m-p/282000#M57253</link>
      <description>&lt;P&gt;works exactly how I wanted it to. I did not know the vtype function, thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 04 Jul 2016 14:11:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Changing-formats-based-on-the-format/m-p/282000#M57253</guid>
      <dc:creator>myname</dc:creator>
      <dc:date>2016-07-04T14:11:22Z</dc:date>
    </item>
  </channel>
</rss>

