<?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: flexible code, macros in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/577013#M13136</link>
    <description>THANK YOU SO MUCH PAIGE, that's exactly what I'm looking for.</description>
    <pubDate>Fri, 26 Jul 2019 18:11:51 GMT</pubDate>
    <dc:creator>changxuosu</dc:creator>
    <dc:date>2019-07-26T18:11:51Z</dc:date>
    <item>
      <title>flexible code, macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/576720#M13096</link>
      <description>&lt;P&gt;Dear SAS community,&lt;/P&gt;&lt;P&gt;I have a question. I am currently building models for a predicting project.&lt;/P&gt;&lt;P&gt;I'm starting with hundreds of variables on hand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Specifically,&amp;nbsp; for example. I have 20 base variables X1,X2,X3...X20.&lt;/P&gt;&lt;P&gt;Each variable has&amp;nbsp;6 transformations. For example&lt;/P&gt;&lt;P&gt;X1_lag1,&lt;/P&gt;&lt;P&gt;X1_lag2,&lt;/P&gt;&lt;P&gt;X1_lead1,&lt;/P&gt;&lt;P&gt;X1_lead2,&lt;/P&gt;&lt;P&gt;X1_avg4m,&lt;/P&gt;&lt;P&gt;X1_avg4m&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I'm having this problem: for certain variables, I need to exclude certain transformation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, for variable X5 and X10 in particular, I need to remove the lead transformation of X5 and X10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote the following code and it works,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SELECT&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DISTINCT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; variable_name &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INTO&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; :selected list&amp;nbsp;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; var_list&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;WHERE&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;upcase(name) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; %X5_LEAD1% &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AND&lt;/FONT&gt; upcase(name) &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt; %X5_LEAD2%&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AND&lt;/FONT&gt; upcase(name) &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt; %X10_LEAD1%&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AND&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; upcase(name) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; %X10_LEAD2%&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But the problem is that in reality, I have hundreads of&amp;nbsp;variables&amp;nbsp;whose certain transformations need to excluded.&lt;/P&gt;&lt;P&gt;what I need now is a more flexible way to write the&amp;nbsp;code that I can change the combination of base variables and transformations that I want to exclude. Currently, the code is manual and not very effective.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried call execute but it doesn't work. I tried write a loop using arrays in a macro but having some difficulties. Can anyone point me to some examples, that'd be great. Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ideally, I want to write a macro, the input has two elements, 1. the list of base variables; 2. the list of tranforms.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then every possible combination of base variable from list 1+transformations from list 2 will be excluded.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then by executing the macro, goals are achieved. No need to manually to update/change/write a complete list of&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;upcase(name) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; %X5_LEAD1% &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AND&lt;/FONT&gt; upcase(name) &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt; %X5_LEAD2%&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AND&lt;/FONT&gt; upcase(name) &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt; %X10_LEAD1%&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AND&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; upcase(name) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; %X10_LEAD2%&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am able to allow the baseline variable be a macro, but still the problem of the code below is that only one variable can be executed at one time. Is there anyway to do a list of variables at one time?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%LET&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; VARN=var5;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SELECT&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DISTINCT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; variable &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;INTO&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; :selected_list&amp;nbsp;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; var_list&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;WHERE&lt;/FONT&gt; &lt;FONT face="Courier New" size="3"&gt;upcase(name) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; cats(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'%'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;VARN."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'_LEAD1%'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;AND&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; upcase(name) &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;not&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;like&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; cats(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'%'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"&amp;amp;VARN."&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'__LEAD2%'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 19:04:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/576720#M13096</guid>
      <dc:creator>changxuosu</dc:creator>
      <dc:date>2019-07-25T19:04:55Z</dc:date>
    </item>
    <item>
      <title>Re: flexible code, macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/576721#M13097</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/193702"&gt;@changxuosu&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;But the problem is that in reality, I have hundreads of&amp;nbsp;variables&amp;nbsp;whose certain transformations need to excluded.&lt;/P&gt;
&lt;P&gt;what I need now is a more flexible way to write the&amp;nbsp;code that I can change the combination of base variables and transformations that I want to exclude. Currently, the code is manual and not very effective.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;How would you know what variables and which transformations need to be excluded? Is this a text list, or an Excel file, or something else?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is it always exclude LEAD1 and LEAD2, or does that vary?&lt;/P&gt;</description>
      <pubDate>Thu, 25 Jul 2019 18:57:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/576721#M13097</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-25T18:57:32Z</dc:date>
    </item>
    <item>
      <title>Re: flexible code, macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/576722#M13098</link>
      <description>thank you Paige. the input of variable/transformation can be excel or text list. I can input it either way. For now, it's always exclude LEAD1 and LEAD2. Only the base variable list changes.</description>
      <pubDate>Thu, 25 Jul 2019 19:00:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/576722#M13098</guid>
      <dc:creator>changxuosu</dc:creator>
      <dc:date>2019-07-25T19:00:24Z</dc:date>
    </item>
    <item>
      <title>Re: flexible code, macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/576724#M13100</link>
      <description>&lt;P&gt;Only the base variable changes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, as an example, we have a SAS data set which contains the base variables of interest (you could read this from a text file or Excel)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data base_variables;
    input base_variable_name $32.;
cards;
x1
x11
x21
x111
paige1
paigemiller1
;

/* Create list of base variable names to exclude */
proc sql noprint;
	select quote(cats(upcase(base_variable_name),'_LEAD1')) into :names1 separated by ',' from base_variables;
	select quote(cats(upcase(base_variable_name),'_LEAD2')) into :names2 separated by ',' from base_variables;
quit;
%put &amp;amp;=names1;
%put &amp;amp;=names2;

proc sql;
    select distinct variable_name into :selected_list from var_list
		where upcase(name) not in (&amp;amp;names1,&amp;amp;names2);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Jul 2019 19:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/576724#M13100</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-25T19:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: flexible code, macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/577013#M13136</link>
      <description>THANK YOU SO MUCH PAIGE, that's exactly what I'm looking for.</description>
      <pubDate>Fri, 26 Jul 2019 18:11:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/577013#M13136</guid>
      <dc:creator>changxuosu</dc:creator>
      <dc:date>2019-07-26T18:11:51Z</dc:date>
    </item>
    <item>
      <title>Re: flexible code, macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/577027#M13139</link>
      <description>a further question is that, is there a way to allow the transformation change as well? in my case there are a bunch of transforms so that if it can be automatically coded, it will be even better. thanks!</description>
      <pubDate>Fri, 26 Jul 2019 18:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/577027#M13139</guid>
      <dc:creator>changxuosu</dc:creator>
      <dc:date>2019-07-26T18:31:38Z</dc:date>
    </item>
    <item>
      <title>Re: flexible code, macros</title>
      <link>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/577049#M13140</link>
      <description>&lt;P&gt;Let's assume that the next time you run the analysis, you want to exclude these transformations&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;LEAD1 LEAD2 BACK7 and MICKEYDOLENZ&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let transforms=LEAD1 LEAD2 BACK7 MICKEYDOLENZ;

data base_variables;
    input base_variable_name $32.;
cards;
x1
x11
x21
x111
paige1
paigemiller1
;

%macro dothis;
/* Create list of base variable names to exclude */
proc sql noprint;
    %do i=1 %to %sysfunc(countw(&amp;amp;transforms));
        %let thisone=%scan(&amp;amp;transforms,&amp;amp;i,%str( ));
	select quote(cats(upcase(base_variable_name),"_&amp;amp;thisone")) into 
            :names&amp;amp;i separated by ',' from base_variables;
    %end;
quit;


proc sql;
    select distinct variable_name into :selected_list from var_list
        where upcase(name) not in 
        (%do i=1 %to %sysfunc(countw(&amp;amp;transforms)); &amp;amp;&amp;amp;names&amp;amp;i
              %if &amp;amp;i&amp;lt;%sysfunc(countw(&amp;amp;transforms)) %then %str(,); %end;);
quit;
%mend;

options mprint;
%dothis&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2019 19:37:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/flexible-code-macros/m-p/577049#M13140</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-07-26T19:37:05Z</dc:date>
    </item>
  </channel>
</rss>

