<?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: Quote a substring inside Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291206#M270042</link>
    <description>&lt;P&gt;Well, you have just given a very good example of why not to use macro language. &amp;nbsp;As I say above, macro language is a method for generating Text only, that is all it does. &amp;nbsp;It has no data constructs (other than text), nor any data processing facilities. &amp;nbsp;It is Base SAS which has all this. &amp;nbsp;For instance, in your example you have a date - which in itself is the number of days since a certain timepoint, represented for humans using a format. &amp;nbsp;In textual context the representation for humans is not a logically processable thing. &amp;nbsp;So using Base SAS the code is very simple:&lt;/P&gt;
&lt;PRE&gt;data temp;
  d=input("20160812",yymmdd8.);
  format d ddmmyy8.;
run;&lt;/PRE&gt;
&lt;P&gt;If you need to use that in macro code you can call symputx('d',put(d,ddmmyy8.));&lt;/P&gt;
&lt;P&gt;However unless there is a very good reason to do so, I would avoid doing it and use Base SAS - if you see code repeating then of course macro-tizing that is useful. &amp;nbsp;This is the way I look at it Base SAS for everything, then if a certain bit of code is repeated, or could be useful elsewhere then macrotize it.&lt;/P&gt;</description>
    <pubDate>Fri, 12 Aug 2016 10:13:11 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-08-12T10:13:11Z</dc:date>
    <item>
      <title>Quote a substring inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291170#M270037</link>
      <description>&lt;DIV class="post-text"&gt;&lt;P&gt;I'm trying to quote a substring of a macro variable. The code is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;%let hola=resuelto!;

%macro prueba(param);
    %let amper=&amp;amp;param;
    %let amper2=%nrbquote(%substr(&amp;amp;param,1,3));
    %put &amp;amp;param;
    %put &amp;amp;amper;
    %put &amp;amp;amper2;
%mend;

%prueba(%nrstr(&amp;amp;hola));&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;In the log, I'm getting:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;WARNING: Apparent symbolic reference HO not resolved.
&amp;amp;hola
&amp;amp;hola
&amp;amp;ho&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The problem is I need to assign &lt;CODE&gt;amper2&lt;/CODE&gt; literally the value &lt;CODE&gt;&amp;amp;ho&lt;/CODE&gt;, without any attempt of resolution, like I do with &lt;CODE&gt;amper&lt;/CODE&gt;, that gets literally the string &lt;CODE&gt;&amp;amp;hola&lt;/CODE&gt;... any idea?&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 12 Aug 2016 07:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291170#M270037</guid>
      <dc:creator>alexdeguays</dc:creator>
      <dc:date>2016-08-12T07:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: Quote a substring inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291182#M270038</link>
      <description>&lt;P&gt;In your code you could only put single quotes around it, otherwise as soon as you try to use double quotes it will treat it as a macro variable. &amp;nbsp;However the real question&amp;nbsp;here, as with any question like this, is why you are trying to use macro code (which is a text generator) to do data manipulation. &amp;nbsp;SAS Base is the programming language, it is designed to manipulate and process data, and has the various constructs and data types to handle all programming functions. &amp;nbsp;Macro is a nice to have to save typing some code, it isn't there as a replacement for SAS Base. &amp;nbsp;Here:&lt;/P&gt;
&lt;PRE&gt;%let hola=resuelto!;

%macro prueba(param);
  data _null_;
    call symputx('amper2',"'"||substr("&amp;amp;param.",1,3)||"'");
    %put &amp;amp;amper2;&lt;BR /&gt;  run;
%mend;

%prueba(%nrstr(&amp;amp;hola));&lt;/PRE&gt;
&lt;P&gt;However, there is no value in the above code at all, it is merely complicated messy programming. &amp;nbsp;Why do you want to do this in the first place? &amp;nbsp;Almost any code you can think of can be done in Base SAS.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 08:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291182#M270038</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-12T08:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: Quote a substring inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291187#M270039</link>
      <description>&lt;PRE&gt;
How about this one ?

%let hola=resuelto!;

%macro prueba(param);
    %let amper=&amp;amp;param;
    %let amper2=&amp;amp;%substr(&amp;amp;param,2,2);
    %put &amp;amp;param;
    %put &amp;amp;amper;
    %put %superq(amper2);
%mend;

%prueba(%nrstr(&amp;amp;hola))

&lt;/PRE&gt;</description>
      <pubDate>Fri, 12 Aug 2016 09:13:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291187#M270039</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-12T09:13:58Z</dc:date>
    </item>
    <item>
      <title>Re: Quote a substring inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291189#M270040</link>
      <description />
      <pubDate>Fri, 12 Aug 2016 09:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291189#M270040</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-12T09:19:12Z</dc:date>
    </item>
    <item>
      <title>Re: Quote a substring inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291204#M270041</link>
      <description>&lt;P&gt;Thank you for your quick answer!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm creating a macro for dates conversion/manipulation. I haven't found a way to change a date value to another value, for example as this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;20160812-&amp;gt;08/12/2016&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 10:03:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291204#M270041</guid>
      <dc:creator>alexdeguays</dc:creator>
      <dc:date>2016-08-12T10:03:57Z</dc:date>
    </item>
    <item>
      <title>Re: Quote a substring inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291206#M270042</link>
      <description>&lt;P&gt;Well, you have just given a very good example of why not to use macro language. &amp;nbsp;As I say above, macro language is a method for generating Text only, that is all it does. &amp;nbsp;It has no data constructs (other than text), nor any data processing facilities. &amp;nbsp;It is Base SAS which has all this. &amp;nbsp;For instance, in your example you have a date - which in itself is the number of days since a certain timepoint, represented for humans using a format. &amp;nbsp;In textual context the representation for humans is not a logically processable thing. &amp;nbsp;So using Base SAS the code is very simple:&lt;/P&gt;
&lt;PRE&gt;data temp;
  d=input("20160812",yymmdd8.);
  format d ddmmyy8.;
run;&lt;/PRE&gt;
&lt;P&gt;If you need to use that in macro code you can call symputx('d',put(d,ddmmyy8.));&lt;/P&gt;
&lt;P&gt;However unless there is a very good reason to do so, I would avoid doing it and use Base SAS - if you see code repeating then of course macro-tizing that is useful. &amp;nbsp;This is the way I look at it Base SAS for everything, then if a certain bit of code is repeated, or could be useful elsewhere then macrotize it.&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 10:13:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291206#M270042</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-12T10:13:11Z</dc:date>
    </item>
    <item>
      <title>Re: Quote a substring inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291208#M270043</link>
      <description>&lt;P&gt;And if your first value is already a SAS date you change the format using the Format statement.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 10:21:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291208#M270043</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-12T10:21:09Z</dc:date>
    </item>
    <item>
      <title>Re: Quote a substring inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291220#M270044</link>
      <description>&lt;P&gt;Thank you, but what if I need a 4-digit year?&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 11:38:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291220#M270044</guid>
      <dc:creator>alexdeguays</dc:creator>
      <dc:date>2016-08-12T11:38:05Z</dc:date>
    </item>
    <item>
      <title>Re: Quote a substring inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291221#M270045</link>
      <description>&lt;P&gt;Then you alter the format length (number at the end) to accomodate a four digit year:&lt;/P&gt;
&lt;PRE&gt;data temp;
  d=input("20160812",yymmdd8.);
  format d ddmmyy10.;
run;&lt;/PRE&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_intervals_sect010.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/etsug/60372/HTML/default/viewer.htm#etsug_intervals_sect010.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 12 Aug 2016 11:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Quote-a-substring-inside-Macro/m-p/291221#M270045</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-12T11:43:45Z</dc:date>
    </item>
  </channel>
</rss>

