<?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: macro function called from within data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963843#M375448</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I can easily have many variables that need conversion from char to varchar format.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This should have been clearly stated in your original post. We shouldn't have to guess why you are going through these gyrations with CALL EXECUTE and Macros and arrays. Please provide sample data set for us to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as I can see, the reason you might want VARCHAR is for CAS data sets, this also should have been clearly stated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;But I saw the usage of macro functions within data steps and cas actions. And I want to learn it and add it to my tool kit.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the things you should learn about macros is when NOT to use them. This is such a case. If the code can be easily written without macros, then macros are not necessary. Examples from me and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt; show you don't need a macro here.&lt;/P&gt;</description>
    <pubDate>Wed, 09 Apr 2025 10:46:25 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2025-04-09T10:46:25Z</dc:date>
    <item>
      <title>macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963830#M375437</link>
      <description>&lt;P&gt;I want to macrotize the following code that works. It doesn't produce an error or log, it just does not terminate.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data public.want;
set public.have;
length batch_id_dt1 batch_id1 varchar(*);



	batch_id_dt1=strip(batch_id_dt);
	drop batch_id_dt;
	rename batch_id_dt1=batch_id_dt;
	
	batch_id1=strip(batch_id);
	drop batch_id;
	rename batch_id1=batch_id;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I'm trying to plug-in the text from a macro function. Here is my failed attempt.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varcharer(name=);
	&amp;amp;name.1=strip(&amp;amp;name);
	drop &amp;amp;name;
	rename &amp;amp;name.1=&amp;amp;name;
%mend;

data public.want;
set public.have(where=(datepart(timestamp)='28mar2025'd));
length batch_id1 varchar(*);
array temp batch_id;

do i=1 to dim(temp);
/* call execute('%varcharer(name=' ||vnamex(temp(i)) || ');'); */
call execute('%varcharer(name=batch_id);');
end;

run;&lt;/CODE&gt;&lt;/PRE&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;</description>
      <pubDate>Wed, 09 Apr 2025 10:01:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963830#M375437</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-04-09T10:01:56Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963834#M375440</link>
      <description>&lt;P&gt;You macro resolves to data step code. It cannot run outside of a data step. CALL EXECUTE queues SAS code to run after the data step finishes, and so is incompatible with the macro.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In addition, the content of your macro will fail as you can't rename a variable like that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In order to write good macro code, you first (this is MANDATORY not optional) have to write code that works without macros and without macro variables for one case, such as for variable named batch_id. You clearly haven't done that because if you had done this you would know you can't rename variables like this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Finally, I don't see why a macro is needed inside an array in this situation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is my solution. Of course this is untested as you haven't provided data for me to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data public.want;
set public.have(where=(datepart(timestamp)='28mar2025'd));
array temp batch_id;
do i=1 to dim(temp);
temp(i)=strip(temp(i));
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So please, next time, you need to do all of these steps&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Describe in words the problem you are trying to solve, so we don't have to guess or figure it out ourselves&lt;/LI&gt;
&lt;LI&gt;Show us code that works without macros and without macro variables for at least one iteration (in this case variable named batch_id)&lt;/LI&gt;
&lt;LI&gt;Provide sample data&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;Do not skip any of these steps&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 10:22:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963834#M375440</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-09T10:22:46Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963835#M375441</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My code works without error, now I want to put it with a macro.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 10:20:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963835#M375441</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-04-09T10:20:01Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963836#M375442</link>
      <description>&lt;P&gt;Why do you need a macro? I wrote code that does what you want without a macro. Macros seem to be an unnecessary complication.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please state in words what you are trying to do.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 10:23:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963836#M375442</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-09T10:23:16Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963838#M375444</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I can easily have many variables that need conversion from char to varchar format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This works:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data public.want;
set public.have;
length batch_id_dt1 batch_id1 varchar(*);



	batch_id_dt1=strip(batch_id_dt);
	drop batch_id_dt;
	rename batch_id_dt1=batch_id_dt;
	
	batch_id1=strip(batch_id);
	drop batch_id;
	rename batch_id1=batch_id;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But for 30 variables I would like to use a macro function. Therefore I've thought about an array for the variables I want to change to varchar.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And looping over the array elements to plug-in the varnames for the maco function.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 10:29:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963838#M375444</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-04-09T10:29:23Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963839#M375445</link>
      <description>&lt;P&gt;Listen to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;, there is no need for macro here.&lt;/P&gt;
&lt;P&gt;You have a list of variables (batch_id_dt and batch_id) you want to strip leading and trailing spaces, just do it with a loop:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data public.want;
 set public.have(where=(datepart(timestamp)='28mar2025'd));
 array temp batch_id_dt batch_id;
 do over temp;
  temp=strip(temp);
 end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 10:30:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963839#M375445</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-09T10:30:43Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963842#M375447</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;I'm not with you. I need to change the batch_id (and x variables more) from char format to varchar format.&lt;/P&gt;
&lt;P&gt;I could produce the text with a proc sql select into, no problem, I can do it.&lt;/P&gt;
&lt;P&gt;But I saw the usage of macro functions within data steps and cas actions. And I want to learn it and add it to my tool kit.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 10:39:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963842#M375447</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-04-09T10:39:41Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963843#M375448</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;I can easily have many variables that need conversion from char to varchar format.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This should have been clearly stated in your original post. We shouldn't have to guess why you are going through these gyrations with CALL EXECUTE and Macros and arrays. Please provide sample data set for us to work with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As far as I can see, the reason you might want VARCHAR is for CAS data sets, this also should have been clearly stated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;But I saw the usage of macro functions within data steps and cas actions. And I want to learn it and add it to my tool kit.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One of the things you should learn about macros is when NOT to use them. This is such a case. If the code can be easily written without macros, then macros are not necessary. Examples from me and &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt; show you don't need a macro here.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 10:46:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963843#M375448</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-09T10:46:25Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963845#M375450</link>
      <description>&lt;P&gt;This should work:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data public.want;
    set public.have;
    length batch_id_dt1 batch_id1 varchar(*);

    %varcharer(name=batch_id);
    %varcharer(name=batch_id_dt);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use proc sql to create a variable containing all the variables that need to be converted, assuming it is named "var_list":&lt;/P&gt;
&lt;PRE&gt;%macro convert();
data public.want;
    set public.have;
    length batch_id_dt1 batch_id1 varchar(*);

    %do i = 1 %to %sysfunc(countw(&amp;amp;var_list, %str( )));
        %let var = %scan(&amp;amp;var_list, &amp;amp;i, %str( ));
        %varcharer(name= &amp;amp;var);
    %end;
run;
%mend convert;
%convert();&lt;/PRE&gt;
&lt;P&gt;Code is untested.&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 10:51:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963845#M375450</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2025-04-09T10:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963847#M375451</link>
      <description>&lt;P&gt;OK, since now it's clear what you want to do, try this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data public.have;
a=" A";
b="  A";
c="   A";
d="    A";
run;

%macro char2varchar(list);
%local V i;
%let i=1;
%let v = %scan(&amp;amp;list., &amp;amp;i., %str( ));
%do %while (&amp;amp;v. NE );
  length &amp;amp;v.1 varchar(*);
	&amp;amp;v.1=strip(&amp;amp;v.);
	drop &amp;amp;v.;
	rename &amp;amp;v.1=&amp;amp;v.;
  %let i= %eval(&amp;amp;i. + 1);
  %let v = %scan(&amp;amp;list., &amp;amp;i., %str( ));
%end;
%mend char2varchar;

options NOmprint;
options mprint;
data public.want;
  set public.have;

  %char2varchar(A B C D)
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;[EDIT:]&lt;/P&gt;
&lt;P&gt;Just to be clear if "public" is not a CAS library, then conversion to varchar is pointless:&lt;/P&gt;
&lt;P&gt;Log:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1    options mprint;
2    data public.want;
3      set public.have;
4
5      %char2varchar(A B C D)
MPRINT(CHAR2VARCHAR):   length A1 varchar(*);
MPRINT(CHAR2VARCHAR):   A1=strip(A);
MPRINT(CHAR2VARCHAR):   drop A;
MPRINT(CHAR2VARCHAR):   rename A1=A;
MPRINT(CHAR2VARCHAR):   length B1 varchar(*);
MPRINT(CHAR2VARCHAR):   B1=strip(B);
MPRINT(CHAR2VARCHAR):   drop B;
MPRINT(CHAR2VARCHAR):   rename B1=B;
MPRINT(CHAR2VARCHAR):   length C1 varchar(*);
MPRINT(CHAR2VARCHAR):   C1=strip(C);
MPRINT(CHAR2VARCHAR):   drop C;
MPRINT(CHAR2VARCHAR):   rename C1=C;
MPRINT(CHAR2VARCHAR):   length D1 varchar(*);
MPRINT(CHAR2VARCHAR):   D1=strip(D);
MPRINT(CHAR2VARCHAR):   drop D;
MPRINT(CHAR2VARCHAR):   rename D1=D;
6    run;

NOTE: VARCHAR data type is not supported by the V9 engine. Variable A has been converted to CHAR data type.
NOTE: VARCHAR data type is not supported by the V9 engine. Variable B has been converted to CHAR data type.
NOTE: VARCHAR data type is not supported by the V9 engine. Variable C has been converted to CHAR data type.
NOTE: VARCHAR data type is not supported by the V9 engine. Variable D has been converted to CHAR data type.
NOTE: There were 1 observations read from the data set PUBLIC.HAVE.
NOTE: The data set PUBLIC.WANT has 1 observations and 4 variables.
NOTE: DATA statement used (Total process time):
      real time           0.04 seconds
      user cpu time       0.03 seconds
      system cpu time     0.03 seconds
      memory              714.18k
      OS Memory           21764.00k
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 10:57:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963847#M375451</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-09T10:57:03Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963850#M375452</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is a macro needed? Why not just an array to do the looping?&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:01:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963850#M375452</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-04-09T11:01:36Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963851#M375453</link>
      <description>&lt;P&gt;That's it.&lt;/P&gt;
&lt;P&gt;My idea is not so silly in my opinion.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here the code that works:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro varcharer(name=);
	&amp;amp;name.1=strip(&amp;amp;name);
	drop &amp;amp;name;
	rename &amp;amp;name.1=&amp;amp;name;
%mend;

%let var_list=batch_id_dt batch_id;


%macro convert();
data public.want;
    set public.have;
    length batch_id_dt1 batch_id1 varchar(*);

    %do i = 1 %to %sysfunc(countw(&amp;amp;var_list, %str( )));
        %let var = %scan(&amp;amp;var_list, &amp;amp;i, %str( ));
        %varcharer(name= &amp;amp;var);
    %end;
run;
%mend convert;
%convert();&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pic10.png" style="width: 701px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/106081i5B967E6AD9784988/image-size/large?v=v2&amp;amp;px=999" role="button" title="pic10.png" alt="pic10.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:01:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963851#M375453</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-04-09T11:01:59Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963853#M375454</link>
      <description>&lt;P&gt;Can I use the these lines within an array loop???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;batch_id_dt1=strip(batch_id_dt);&lt;BR /&gt;drop batch_id_dt;&lt;BR /&gt;rename batch_id_dt1=batch_id_dt;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:04:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963853#M375454</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-04-09T11:04:02Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963854#M375455</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is a macro needed? Why not just an array to do the looping?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;For moving the values from char to varchar an array is sufficient, but imho not to drop the char-variables and rename the varchar-vars. &lt;/P&gt;
&lt;P&gt;With more spare-time i would have suggested a data-null-step writing the code transforming-step without any macro statements. &lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:07:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963854#M375455</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2025-04-09T11:07:36Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963855#M375456</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/127222"&gt;@acordes&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Can I use the these lines within an array loop???&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;batch_id_dt1=strip(batch_id_dt);&lt;BR /&gt;drop batch_id_dt;&lt;BR /&gt;rename batch_id_dt1=batch_id_dt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;No, you can't. The variable names can't be inserted by using vname[x].&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:09:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963855#M375456</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2025-04-09T11:09:09Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963856#M375457</link>
      <description>&lt;P&gt;Thanks Bart, I'll test later.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for sure you're right&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;to call me on stating well the problem. If I use public as library for me it's always a caslib, but yes, I should have said clearly.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And to generate test data here in this case I've found it to complicated or time-consuming.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963856#M375457</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-04-09T11:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963859#M375458</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data public.have;
a=" A";
b="  A";
c="   A";
d="    A";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Not "that" time consuming &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &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;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 11:26:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963859#M375458</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-04-09T11:26:16Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963860#M375459</link>
      <description>Ok, too lazy and less resourceful.</description>
      <pubDate>Wed, 09 Apr 2025 11:38:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963860#M375459</guid>
      <dc:creator>acordes</dc:creator>
      <dc:date>2025-04-09T11:38:44Z</dc:date>
    </item>
    <item>
      <title>Re: macro function called from within data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963892#M375468</link>
      <description>&lt;P&gt;In general it is not a good idea to write macros that reference "magic" parameters.&amp;nbsp; That is macro variables that are not part of their input.&amp;nbsp; Or if you must do it then clearly document in the header of the macro what external macro variables it will be referencing.&lt;/P&gt;
&lt;P&gt;So just make the macro accept space delimited list of names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro char_to_varchar(varlist);
%local i name ;
%do i=1 %to %sysfunc(countw(&amp;amp;varlist,%str( ),q));
  %let name=%scan(&amp;amp;varlist,%str( ),q);
  length __&amp;amp;name varchar(*) ;
	__&amp;amp;name=strip(&amp;amp;name);
	drop &amp;amp;name;
	rename __&amp;amp;name.=&amp;amp;name;
%end;
%mend char_to_varchar;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you can all it the middle of a data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data public.want;
  set public.have;
  %char_to_varchar(batch_id_dt batch_id)
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want to build the list of names into macro variable you can do that.&lt;/P&gt;
&lt;P&gt;For example you might do this to create the macro variable VAR_LIST with all character variables whose name starts with BATCH.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc transpose data=public.have(obs=0 keep=batch: ) out=names;
  var _character_;
run;
proc sql noprint;
  select nliteral(_name_) into :var_list separated by ' '
    from names
  ;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And then you can use that macro variable in your call to the macro.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data public.want;
  set public.have;
  %char_to_varchar(&amp;amp;var_list)
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 09 Apr 2025 14:29:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-function-called-from-within-data-step/m-p/963892#M375468</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-04-09T14:29:13Z</dc:date>
    </item>
  </channel>
</rss>

