<?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: Setting a New Variable to a Another Variable and Keep DateTime Format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Setting-a-New-Variable-to-a-Another-Variable-and-Keep-DateTime/m-p/784130#M250170</link>
    <description>&lt;P&gt;Use a FORMAT or ATTRIB statement to assign the wanted format to the new variable.&lt;/P&gt;</description>
    <pubDate>Sat, 04 Dec 2021 23:04:50 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-12-04T23:04:50Z</dc:date>
    <item>
      <title>Setting a New Variable to a Another Variable and Keep DateTime Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-a-New-Variable-to-a-Another-Variable-and-Keep-DateTime/m-p/784123#M250166</link>
      <description>&lt;P&gt;Hello All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm trying to create a new variable to set to another datetime variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data End_Date_Time ;&lt;BR /&gt;set IN_BOTH;&lt;BR /&gt;A_ETM_&amp;amp;ADAMEAETIME. = A_&amp;amp;ADAMEAETIME.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The original variable A_&amp;amp;ADAMEAETIME has the following value format:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MikeXue_0-1638649266540.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66410iD2A72C2DB7A924D9/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MikeXue_0-1638649266540.png" alt="MikeXue_0-1638649266540.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, my new variable A_ETM_&amp;amp;ADAMEAETIME as the following format:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="MikeXue_1-1638649307686.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/66411i3E8CE622CA9CC8BA/image-size/medium?v=v2&amp;amp;px=400" role="button" title="MikeXue_1-1638649307686.png" alt="MikeXue_1-1638649307686.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What do I do need to in order to keep the formatting of the original variable in my new variable? Also, I&amp;nbsp;&lt;U&gt;do not&lt;/U&gt; want to rename the variable due to circumstances of the data and overlapping that can occur. So creating a new variable is a must.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help in advance!&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 20:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-a-New-Variable-to-a-Another-Variable-and-Keep-DateTime/m-p/784123#M250166</guid>
      <dc:creator>MikeXue</dc:creator>
      <dc:date>2021-12-04T20:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a New Variable to a Another Variable and Keep DateTime Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-a-New-Variable-to-a-Another-Variable-and-Keep-DateTime/m-p/784130#M250170</link>
      <description>&lt;P&gt;Use a FORMAT or ATTRIB statement to assign the wanted format to the new variable.&lt;/P&gt;</description>
      <pubDate>Sat, 04 Dec 2021 23:04:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-a-New-Variable-to-a-Another-Variable-and-Keep-DateTime/m-p/784130#M250170</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-12-04T23:04:50Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a New Variable to a Another Variable and Keep DateTime Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-a-New-Variable-to-a-Another-Variable-and-Keep-DateTime/m-p/784153#M250186</link>
      <description>&lt;P&gt;The easiest way is to just define a format for the new variable. In below code that's option 1.&lt;/P&gt;
&lt;P&gt;If you want to create the new variable using exactly the attributes of another variable without having to define them explicitly then option 2 provides an approach for this.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  a_etm=datetime();
  format a_etm datetime.;
run;

/* option 1 */
data want1;
  set have;
  format new_var datetime.;
  new_var=mapping;
run;

/* option 2 */
data mapping;
  stop;
  set have(keep=a_etm);
  rename a_etm=new_var;
run;

data want;
  set have;
  if 0 then set mapping;
  new_var=a_etm;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Dec 2021 09:30:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-a-New-Variable-to-a-Another-Variable-and-Keep-DateTime/m-p/784153#M250186</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2021-12-05T09:30:18Z</dc:date>
    </item>
    <item>
      <title>Re: Setting a New Variable to a Another Variable and Keep DateTime Format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Setting-a-New-Variable-to-a-Another-Variable-and-Keep-DateTime/m-p/784160#M250190</link>
      <description>&lt;P&gt;You don't need to create a new SAS data set for this. Just put the FORMAT statement in the same data step that creates the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or if the dataset containing this new variable (unformatted) already exists, just modify the metadata by using PROC DATASETS so that this new variable has the desired format.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc datasets library=work nolist;
    modify End_Date_Time;
    format A_ETM_&amp;amp;ADAMEAETIME datetime16.;
run; quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 05 Dec 2021 11:58:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Setting-a-New-Variable-to-a-Another-Variable-and-Keep-DateTime/m-p/784160#M250190</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-12-05T11:58:17Z</dc:date>
    </item>
  </channel>
</rss>

