<?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: Assign same format to multiple variables that end with DT in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772866#M245429</link>
    <description>&lt;P&gt;Ah I see... Unfortunately this dataset is strict on naming and ordering of variables.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 07 Oct 2021 19:43:18 GMT</pubDate>
    <dc:creator>mariko5797</dc:creator>
    <dc:date>2021-10-07T19:43:18Z</dc:date>
    <item>
      <title>Assign same format to multiple variables that end with DT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772841#M245422</link>
      <description>&lt;P&gt;Is there a way to have all variables that end with DT to be formatted DATE9., all variables that end with TM to be formatted TIME5., and all variables ending in DTM to be formatted DATETIME16.?&lt;/P&gt;
&lt;P&gt;I tried:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format :sdt date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But FORMAT is no longer colored blue with the colon there.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 18:17:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772841#M245422</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-10-07T18:17:54Z</dc:date>
    </item>
    <item>
      <title>Re: Assign same format to multiple variables that end with DT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772853#M245425</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/311553"&gt;@mariko5797&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Is there a way to have all variables that end with DT to be formatted DATE9., all variables that end with TM to be formatted TIME5., and all variables ending in DTM to be formatted DATETIME16.?&lt;/P&gt;
&lt;P&gt;I tried:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format :sdt date9.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But FORMAT is no longer colored blue with the colon there.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you think that you want to use short hand lists then do so when creating the variables. You can't use a list that starts with ":"&amp;nbsp; . Name the variables starting with DT and you can use DT: with them, similar with your TM or DTM, start the names that way.&lt;/P&gt;
&lt;P&gt;Or if the variables are in adjacent columns you can use a list with 2 dashes:&amp;nbsp; FirstDT -- TheLastDT&amp;nbsp; . But that only will work if they are in adjacent columns of the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Another way would be get the names of the variables into a data step and use that to write Proc Datasets code to assign a format (or other property) after the data set is created.&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:14:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772853#M245425</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-10-07T19:14:02Z</dc:date>
    </item>
    <item>
      <title>Re: Assign same format to multiple variables that end with DT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772856#M245427</link>
      <description>&lt;P&gt;If &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt; 's solution doesn't work for you (it's the logical way and is what I would suggest it, too), this is one way I've dealt with the issue if I have many variables scattered across the data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You essentially extract the information from the dictionary tables within SAS which provide meta-level information about the data sets. An example data set:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input id val1 val2 start_dt :mmddyy10. end_dt :mmddyy10.;
datalines;
1 2 3 11/20/2020 11/13/2021
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which results in:&lt;/P&gt;
&lt;PRE&gt;Obs id val1 val2 start_dt end_dt 
1 1 2 3 22239 22597 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We have start_dt and end_dt at the end. As @ballardw mentioned, you can use the double hyphen to take care of it here, but I don't know if that's how your data are structured. So, we can extract all those variable names that contain `dt`.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
	select
				name
					into: date_vars separated by " "
	from
				dictionary.columns
	where
				upcase(libname) = "WORK" and upcase(memname) = "HAVE" and upcase(name) contains ("DT");
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note, I used the `upcase` function to reduce any potential issues if you re-ran this code. This extracts those variables (e.g. `name`) in the WORK.HAVE data set that contain "dt". It stores them in a single macro variable, `date_vars`, where they are separated by a single space.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I can then run this to apply the format to those variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc print data = have;
format &amp;amp;date_vars. date9.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;Obs id val1 val2 start_dt end_dt 
1 1 2 3 20NOV2020 13NOV2021 
&lt;/PRE&gt;
&lt;P&gt;I forgot to add that there may be additional complexities in your variable names that I didn't account for. If there are other variables with "dt" in them, they will be picked up here, too. We may need to use another function to get exactly what you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:35:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772856#M245427</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-10-07T19:35:06Z</dc:date>
    </item>
    <item>
      <title>Re: Assign same format to multiple variables that end with DT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772866#M245429</link>
      <description>&lt;P&gt;Ah I see... Unfortunately this dataset is strict on naming and ordering of variables.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772866#M245429</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-10-07T19:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Assign same format to multiple variables that end with DT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772867#M245430</link>
      <description>&lt;P&gt;What is dictionary.columns from? Is that build into SAS?&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:47:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772867#M245430</guid>
      <dc:creator>mariko5797</dc:creator>
      <dc:date>2021-10-07T19:47:40Z</dc:date>
    </item>
    <item>
      <title>Re: Assign same format to multiple variables that end with DT</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772869#M245432</link>
      <description>&lt;P&gt;It basically stores higher level information about variables and their attributes within a data set. I'm probably not explaining that well, but here's something that explains it better than I can. It is active whenever you start a session.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/070-30.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/070-30.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 07 Oct 2021 19:52:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Assign-same-format-to-multiple-variables-that-end-with-DT/m-p/772869#M245432</guid>
      <dc:creator>maguiremq</dc:creator>
      <dc:date>2021-10-07T19:52:55Z</dc:date>
    </item>
  </channel>
</rss>

