<?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: How to call a macro in data step? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498326#M132400</link>
    <description>&lt;P&gt;I ran the following code but I'm not getting the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let reporting_date=30jun2018;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt; KNDATLD= ' ';&lt;BR /&gt; output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data tmp;&lt;BR /&gt; set test;&lt;/P&gt;
&lt;P&gt;if missing(KNDATLD) then&lt;BR /&gt; KNDATLD = "&amp;amp;reporting_date."d;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
26         %let reporting_date=30jun2018;
27         
28         data test;
29         	KNDATLD= ' ';
30         	output;
31         run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

32         
33         data tmp;
34         	set test;
2                                                          The SAS System                           11:13 Monday, September 24, 2018

35         
36         	if missing(KNDATLD) then
37         		KNDATLD = "&amp;amp;reporting_date."d;
38         run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      37:2   
NOTE: Invalid character data, 21365.00 , at line 37 column 2.
KNDATLD=* _ERROR_=1 _N_=1
NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TMP has 1 observations and 1 variables.
NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted by the "BEST" format.
NOTE: DATA statement used (Total process time):&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Desired Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;30Jun2018 (should be in character)&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 24 Sep 2018 09:20:27 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2018-09-24T09:20:27Z</dc:date>
    <item>
      <title>How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498305#M132391</link>
      <description>&lt;P&gt;Could you please guide me to resolve the error? KNDATLD is a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Code:&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;%let reporting_date=30jun2018;
data test;
KNDATLD= ' ';output;
run;

data tmp;
set test;
If KNDATLD=' ' then &amp;amp;reporting_date.;
else KNDATLD;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Log:&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;PRE&gt;&lt;CODE class=" language-sas"&gt;26         %let reporting_date=30jun2018;
27         data test;
28         KNDATLD= ' ';output;
29         run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

30         
31         data tmp;
32         set test;
33         If KNDATLD=' ' then &amp;amp;reporting_date.;
NOTE: Line generated by the macro variable "REPORTING_DATE".
2                                                          The SAS System                           09:35 Monday, September 24, 2018

33          30jun2018
            __
            180
34         else KNDATLD;
                _______
                180
ERROR 180-322: Statement is not valid or it is used out of proper order.

35         run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.TMP may be incomplete.  When this step was stopped there were 0 observations and 1 variables.
WARNING: Data set WORK.TMP was not replaced because this step was stopped.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 07:42:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498305#M132391</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-09-24T07:42:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498308#M132392</link>
      <description>&lt;P&gt;Macro is a&amp;nbsp;&lt;U&gt;&lt;STRONG&gt;find and replace system&lt;/STRONG&gt;&lt;/U&gt; nothing more, and works before code is executed.&amp;nbsp; The simplest way to see what is going wrong is to copy and paste the macro code into your SAS code - that is the code that gets executed - then see if it is valid SAS.&amp;nbsp; So lets take your example:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; tmp&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  set&lt;/SPAN&gt; test&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  if&lt;/SPAN&gt; kndatld&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;' '&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; &lt;SPAN class="token operator"&gt;30jun2018&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  else&lt;/SPAN&gt; kndatld&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Does this look like valid Base SAS?&amp;nbsp; No, you have a then statement, with just a set of characters after it, no asignement, no string delimiters, and then an else, again with no delimiter or reference of what to do.&amp;nbsp; Lets assume that you want to assign xyz to a value:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; tmp&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  set&lt;/SPAN&gt; test&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  if&lt;/SPAN&gt; kndatld&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;' '&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; xyz="&lt;SPAN class="token operator"&gt;30jun2018"&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;  else&lt;/SPAN&gt; xyz=kndatld&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 07:46:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498308#M132392</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-24T07:46:26Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498310#M132393</link>
      <description>&lt;P&gt;Once again:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;The macro preprocessor is a code generator. See it as a simple text replacement system. That's exactly what happens. You have to put &lt;U&gt;valid SAS code&lt;/U&gt; into your macro variable for this to work.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Start with valid SAS code, then put the code snippet into the macrovar.&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp;
set test;
If KNDATLD=' ' then 30jun2018;
else KNDATLD;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;is very simply NOT valid SAS code.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 07:49:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498310#M132393</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-24T07:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498311#M132394</link>
      <description>&lt;P&gt;You need an assignment after then and you need to enclose macro-variables in double-quotes if they contain text. The else-statement could be skipped, if you want to change the value of kndatld.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp;
  set test;

  if missing(KNDATLD) then KNDATLD = "&amp;amp;reporting_date."d;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 24 Sep 2018 07:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498311#M132394</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-09-24T07:49:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498314#M132395</link>
      <description>&lt;P&gt;On second thought, it looks like you are mixing data step with SQL code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table tmp as
select
  case
    when KNDATLD=' '
    then "&amp;amp;reporting_date."d;
    else KNDATLD
  end as KNDATLD
from test;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;would work. Note how the macrovar is enclosed in "..."d!&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 07:54:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498314#M132395</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-24T07:54:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498326#M132400</link>
      <description>&lt;P&gt;I ran the following code but I'm not getting the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let reporting_date=30jun2018;&lt;/P&gt;
&lt;P&gt;data test;&lt;BR /&gt; KNDATLD= ' ';&lt;BR /&gt; output;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;data tmp;&lt;BR /&gt; set test;&lt;/P&gt;
&lt;P&gt;if missing(KNDATLD) then&lt;BR /&gt; KNDATLD = "&amp;amp;reporting_date."d;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
26         %let reporting_date=30jun2018;
27         
28         data test;
29         	KNDATLD= ' ';
30         	output;
31         run;

NOTE: The data set WORK.TEST has 1 observations and 1 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds
      

32         
33         data tmp;
34         	set test;
2                                                          The SAS System                           11:13 Monday, September 24, 2018

35         
36         	if missing(KNDATLD) then
37         		KNDATLD = "&amp;amp;reporting_date."d;
38         run;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column).
      37:2   
NOTE: Invalid character data, 21365.00 , at line 37 column 2.
KNDATLD=* _ERROR_=1 _N_=1
NOTE: There were 1 observations read from the data set WORK.TEST.
NOTE: The data set WORK.TMP has 1 observations and 1 variables.
NOTE: At least one W.D format was too small for the number to be printed. The decimal may be shifted by the "BEST" format.
NOTE: DATA statement used (Total process time):&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Desired Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;30Jun2018 (should be in character)&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 09:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498326#M132400</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-09-24T09:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498328#M132401</link>
      <description>&lt;P&gt;Log!&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token statement"&gt;NOTE&lt;/SPAN&gt;: Numeric values have been converted to character values at the places given &lt;SPAN class="token statement"&gt;by&lt;/SPAN&gt;: &lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;Line&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;:&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;Column&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;
      &lt;SPAN class="token number"&gt;37&lt;/SPAN&gt;:&lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;   
&lt;SPAN class="token statement"&gt;NOTE&lt;/SPAN&gt;: Invalid character &lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;21365.00&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; at line &lt;SPAN class="token number"&gt;37&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;column&lt;/SPAN&gt; &lt;SPAN class="token number"&gt;2&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Clue is there, "..."d = date literal = numeric, variable is text.&amp;nbsp; Remove the d to have a text string.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 09:22:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498328#M132401</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-24T09:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498329#M132402</link>
      <description>&lt;P&gt;if I remove "d", I'm getting only output as "3"&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 09:23:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498329#M132402</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-09-24T09:23:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498330#M132403</link>
      <description>&lt;P&gt;Sorry, my fault. Automatically added the "d", because i hardly ever have dates as text.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 09:24:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498330#M132403</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-09-24T09:24:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498331#M132404</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Sorry, my fault. Automatically added the "d", because i hardly ever have dates as text.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Of course, as you don't define the length of the variable it is set to 1 when assigning the blank.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 09:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498331#M132404</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-09-24T09:25:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498332#M132405</link>
      <description>&lt;PRE class=" language-sas"&gt;%let reporting_date=30jun2018;&lt;BR /&gt;&lt;BR /&gt;data test;&lt;BR /&gt; length kndatld $20;&lt;BR /&gt; kndatld='';&lt;BR /&gt; output;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data tmp;&lt;BR /&gt; set test;&lt;BR /&gt; if kndatld='' then kndatld="&amp;amp;reporting_date.";&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 09:34:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498332#M132405</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-24T09:34:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to call a macro in data step?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498359#M132418</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/8409"&gt;@Babloo&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;&lt;BR /&gt;
&lt;P&gt;Desired Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;30Jun2018 (should be in character)&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And what for would you want to have that unusable string? Store dates as SAS dates, everything else only causes additional work when needed.&lt;/P&gt;
&lt;P&gt;No place in the world uses the date9. format for display in reports, it's either a ddmmyy, a mmddyy or a yymmdd format.&lt;/P&gt;</description>
      <pubDate>Mon, 24 Sep 2018 11:27:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-call-a-macro-in-data-step/m-p/498359#M132418</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-09-24T11:27:29Z</dc:date>
    </item>
  </channel>
</rss>

