<?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: Create a new macro var based on another macro var in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634308#M188257</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; &amp;nbsp; Your picture idea will work if you use the DATATYPE option in the picture statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;     picture dt   low-high='%0d_%0m_%G' (datatype=date)  ;run;

%let yymmdd=200323;
%let want=%sysfunc(putn(%sysfunc(inputn(&amp;amp;yymmdd,yymmdd6.)),dt.));
%put &amp;amp;=want;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The datatype option allows you to use picture&amp;nbsp; directives.&amp;nbsp; In this case &amp;nbsp; %0d (day of month with leading zero),&amp;nbsp; %0m (month), and %G (4-digit year), &amp;nbsp;&amp;nbsp; with&amp;nbsp; _ as separators.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course it would be nice if the ddmmyyxw.&amp;nbsp; format allowed underscore characters.&amp;nbsp; But if the OP were&amp;nbsp; happy with, say a colon separator, then you can use a pre-defined variant of ddmmyyxw.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;381  %let yymmdd=200323;
382  %let want=%sysfunc(putn(%sysfunc(inputn(&amp;amp;yymmdd,yymmdd6.)),ddmmyyC10.));
383  %put &amp;amp;=want;
WANT=23:03:2020
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If SAS allowed a U (for underscore) where I put a C, no picture statement would be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, whenever I am using a date expression as a macro var value, I try to avoid the YYYYMMDD (unless I'm sorting by macro values) or DDMMYY layouts.&amp;nbsp; Instead I often do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mydate=23mar2020;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which allows me to trivially use &amp;nbsp;&amp;nbsp; "&amp;amp;mydate"d as date expressions in SAS code,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or %sysevalf("&amp;amp;mydate"d) &amp;nbsp; when it has to be evaluated at the macro level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks to Richard de Venezia for the %sysevalf tip.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 24 Mar 2020 00:32:30 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2020-03-24T00:32:30Z</dc:date>
    <item>
      <title>Create a new macro var based on another macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634107#M188192</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let  YYMMDD=200323;
I want to create a new macro variable that will get value 23_03_2020
What is the way to do it please?&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 23 Mar 2020 13:46:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634107#M188192</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-03-23T13:46:45Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new macro var based on another macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634111#M188196</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let newvar=%substr(&amp;amp;yymmdd,5,2)_%substr(&amp;amp;yymmdd,3,2)_20%substr(&amp;amp;yymmdd,1,2);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Mar 2020 13:55:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634111#M188196</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-03-23T13:55:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new macro var based on another macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634116#M188199</link>
      <description>&lt;P&gt;For what it's worth, here is another approach&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let  YYMMDD=200323;

%let want=%sysfunc(translate(%sysfunc(inputn(&amp;amp;yymmdd,yymmdd8.),ddmmyyd10.),'_','-'));
%put &amp;amp;=want;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;LOG:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1803  %let  YYMMDD=200323;
1804
1805  %let want=%sysfunc(translate(%sysfunc(inputn(&amp;amp;yymmdd,yymmdd8.),ddmmyyd10.),'_','-'));
1806  %put &amp;amp;=want;
WANT=23_03_2020
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Mar 2020 14:12:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634116#M188199</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-23T14:12:09Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new macro var based on another macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634122#M188202</link>
      <description>&lt;P&gt;Some fun with PICTURE formats instead of translation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
 picture dt
   low-high='99_99_9999' ;
run;


%let  YYMMDD=200323;

%let want=%sysfunc(putn(%sysfunc(inputn(&amp;amp;yymmdd,yymmdd8.),ddmmyyn8.),dt.));
%put &amp;amp;=want;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1841  %let  YYMMDD=200323;
1842
1843  %let want=%sysfunc(putn(%sysfunc(inputn(&amp;amp;yymmdd,yymmdd8.),ddmmyyn8.),dt.));
1844  %put &amp;amp;=want;
WANT=23_03_2020
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I would like bring this need to the attention of elders like&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4"&gt;@ChrisHemedinger&lt;/a&gt;&amp;nbsp; &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;the idea of&amp;nbsp; having a '_' also as a separator&amp;nbsp;DDMMYY&lt;SPAN class="xis-userSuppliedValue"&gt;x&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;Format as it seems this option is currently unavailable.&amp;nbsp; Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp; for the question!&lt;/P&gt;
&lt;H1 id="p1uyobuitxtzhwn10vu2ri4v0p00" class="xis-title"&gt;&amp;nbsp;&lt;/H1&gt;</description>
      <pubDate>Mon, 23 Mar 2020 14:25:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634122#M188202</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-23T14:25:07Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new macro var based on another macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634308#M188257</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt; &amp;nbsp; Your picture idea will work if you use the DATATYPE option in the picture statement:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;     picture dt   low-high='%0d_%0m_%G' (datatype=date)  ;run;

%let yymmdd=200323;
%let want=%sysfunc(putn(%sysfunc(inputn(&amp;amp;yymmdd,yymmdd6.)),dt.));
%put &amp;amp;=want;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The datatype option allows you to use picture&amp;nbsp; directives.&amp;nbsp; In this case &amp;nbsp; %0d (day of month with leading zero),&amp;nbsp; %0m (month), and %G (4-digit year), &amp;nbsp;&amp;nbsp; with&amp;nbsp; _ as separators.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course it would be nice if the ddmmyyxw.&amp;nbsp; format allowed underscore characters.&amp;nbsp; But if the OP were&amp;nbsp; happy with, say a colon separator, then you can use a pre-defined variant of ddmmyyxw.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;381  %let yymmdd=200323;
382  %let want=%sysfunc(putn(%sysfunc(inputn(&amp;amp;yymmdd,yymmdd6.)),ddmmyyC10.));
383  %put &amp;amp;=want;
WANT=23:03:2020
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If SAS allowed a U (for underscore) where I put a C, no picture statement would be needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW, whenever I am using a date expression as a macro var value, I try to avoid the YYYYMMDD (unless I'm sorting by macro values) or DDMMYY layouts.&amp;nbsp; Instead I often do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let mydate=23mar2020;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which allows me to trivially use &amp;nbsp;&amp;nbsp; "&amp;amp;mydate"d as date expressions in SAS code,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;or %sysevalf("&amp;amp;mydate"d) &amp;nbsp; when it has to be evaluated at the macro level.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks to Richard de Venezia for the %sysevalf tip.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 00:32:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634308#M188257</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-03-24T00:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new macro var based on another macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634310#M188259</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp; for lending your time and furnishing finer details. So, OP, I et al got more for our money &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"&lt;SPAN&gt;Of course&lt;U&gt; it would be nice i&lt;/U&gt;f the ddmmyyxw.&amp;nbsp; format allowed underscore characters.&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/EM&gt;&lt;SPAN&gt;&lt;EM&gt;If SAS allowed a U (for underscore) where I put a C, no picture statement would be needed&lt;/EM&gt;."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I'm glad to note that concurrence and that really made my day on the community. Cheers!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 24 Mar 2020 00:43:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634310#M188259</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-03-24T00:43:13Z</dc:date>
    </item>
    <item>
      <title>Re: Create a new macro var based on another macro var</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634348#M188268</link>
      <description>&lt;P&gt;And just for fun here an option using regex&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let  YYMMDD=200323;
%let want=%sysfunc(prxchange(s/(\d\d)(\d\d)(\d\d)/20\3_\2_\1/oi,1,&amp;amp;yymmdd));
%put &amp;amp;=want;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 24 Mar 2020 06:44:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Create-a-new-macro-var-based-on-another-macro-var/m-p/634348#M188268</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-03-24T06:44:23Z</dc:date>
    </item>
  </channel>
</rss>

