<?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: Using macro function in DATA step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-function-in-DATA-step/m-p/238165#M43728</link>
    <description>&lt;P&gt;The statement works, but it doesn't do what you are expecting.&amp;nbsp; Macro language is not processing your data.&amp;nbsp; It has an entirely different function.&amp;nbsp; It generates the SAS language statements that will then process your data.&amp;nbsp; So this statement is legal:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let newvar = %substr(CHAR_VAR, 1, 4);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It gives &amp;amp;NEWVAR the value CHAR (the first four characters in "CHAR_VAR").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means that %SUBSTR works, and gives you a program that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data check;&lt;/P&gt;
&lt;P&gt;var = CHAR;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably, this is not the program that you intended to generate.&amp;nbsp; So work backwards.&amp;nbsp; Start with what you would like to see as a SAS program, and then see where macro language might be able to help you get there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
    <pubDate>Mon, 07 Dec 2015 21:01:51 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-12-07T21:01:51Z</dc:date>
    <item>
      <title>Using macro function in DATA step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-function-in-DATA-step/m-p/238160#M43727</link>
      <description>&lt;P&gt;This works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%put %substr(CHAR_DATA,1,4);&lt;/PRE&gt;&lt;P&gt;But when used in DATA step it does not work.&lt;/P&gt;&lt;PRE&gt;data check;
  var=%substr(CHAR_DATA,1,4);
run;
******* or *********;
%macro test;
data check;
  var=%substr(CHAR_DATA,1,4);
run;
%mend test;
%test&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for explanation.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 20:52:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-function-in-DATA-step/m-p/238160#M43727</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2015-12-07T20:52:46Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro function in DATA step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-function-in-DATA-step/m-p/238165#M43728</link>
      <description>&lt;P&gt;The statement works, but it doesn't do what you are expecting.&amp;nbsp; Macro language is not processing your data.&amp;nbsp; It has an entirely different function.&amp;nbsp; It generates the SAS language statements that will then process your data.&amp;nbsp; So this statement is legal:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let newvar = %substr(CHAR_VAR, 1, 4);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It gives &amp;amp;NEWVAR the value CHAR (the first four characters in "CHAR_VAR").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That means that %SUBSTR works, and gives you a program that looks like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data check;&lt;/P&gt;
&lt;P&gt;var = CHAR;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Probably, this is not the program that you intended to generate.&amp;nbsp; So work backwards.&amp;nbsp; Start with what you would like to see as a SAS program, and then see where macro language might be able to help you get there.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2015 21:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-function-in-DATA-step/m-p/238165#M43728</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-12-07T21:01:51Z</dc:date>
    </item>
  </channel>
</rss>

