<?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: Write short code on top but run it in middle of a big code file in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/546964#M151516</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;There is a piece of my code that need manual change from time to time.&lt;/P&gt;
&lt;P&gt;Thus, I want to put this piece on top and then call it in the middle of my full code.&lt;/P&gt;
&lt;P&gt;Can you please show me how to do it?&lt;/P&gt;
&lt;P&gt;Thank you so much,&lt;/P&gt;
&lt;P&gt;HHCFX&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the sample below, I put that 3 line on top and it supposed to be execute at the end&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;data final; set want1;
if id=2;run;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&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;*my 3 lines that need manual changes;
data final; set want1;
if id=2;run;



*Main code----------------------;

data have;
input ID var;
datalines;
1 2
2 3
3 4
;run;

proc means data=have noprint;
by id;
var var;
output out=want1
sum=sum_var; run;

*Call the 3 line code here;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do you need to change from time to time?&lt;/P&gt;
&lt;P&gt;This is a likely candidate for a macro. Define the macro at the top of the code and then call with needed changes with your changes as parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro helper(outset=work.final, inset=work.want1, idvar=id, id=2);
data &amp;amp;outset.;
   set &amp;amp;inset.;
   if &amp;amp;idvar. = &amp;amp;id.;
run;
%mend;




proc means data = sashelp.class;
   class sex;
   var height;
   output out=work.summary sum=sum_var;
run;

%helper(inset=work.summary, idvar=sex, id='M')


&lt;/PRE&gt;</description>
    <pubDate>Thu, 28 Mar 2019 17:23:46 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2019-03-28T17:23:46Z</dc:date>
    <item>
      <title>Write short code on top but run it in middle of a big code file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/546957#M151513</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;There is a piece of my code that need manual change from time to time.&lt;/P&gt;
&lt;P&gt;Thus, I want to put this piece on top and then call it in the middle of my full code.&lt;/P&gt;
&lt;P&gt;Can you please show me how to do it?&lt;/P&gt;
&lt;P&gt;Thank you so much,&lt;/P&gt;
&lt;P&gt;HHCFX&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the sample below, I put that 3 line on top and it supposed to be execute at the end&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;data final; set want1;
if id=2;run;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&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;*my 3 lines that need manual changes;
data final; set want1;
if id=2;run;



*Main code----------------------;

data have;
input ID var;
datalines;
1 2
2 3
3 4
;run;

proc means data=have noprint;
by id;
var var;
output out=want1
sum=sum_var; run;

*Call the 3 line code here;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Mar 2019 17:11:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/546957#M151513</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-03-28T17:11:41Z</dc:date>
    </item>
    <item>
      <title>Re: Write short code on top but run it in middle of a big code file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/546964#M151516</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;There is a piece of my code that need manual change from time to time.&lt;/P&gt;
&lt;P&gt;Thus, I want to put this piece on top and then call it in the middle of my full code.&lt;/P&gt;
&lt;P&gt;Can you please show me how to do it?&lt;/P&gt;
&lt;P&gt;Thank you so much,&lt;/P&gt;
&lt;P&gt;HHCFX&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In the sample below, I put that 3 line on top and it supposed to be execute at the end&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;data final; set want1;
if id=2;run;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&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;*my 3 lines that need manual changes;
data final; set want1;
if id=2;run;



*Main code----------------------;

data have;
input ID var;
datalines;
1 2
2 3
3 4
;run;

proc means data=have noprint;
by id;
var var;
output out=want1
sum=sum_var; run;

*Call the 3 line code here;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What do you need to change from time to time?&lt;/P&gt;
&lt;P&gt;This is a likely candidate for a macro. Define the macro at the top of the code and then call with needed changes with your changes as parameters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%macro helper(outset=work.final, inset=work.want1, idvar=id, id=2);
data &amp;amp;outset.;
   set &amp;amp;inset.;
   if &amp;amp;idvar. = &amp;amp;id.;
run;
%mend;




proc means data = sashelp.class;
   class sex;
   var height;
   output out=work.summary sum=sum_var;
run;

%helper(inset=work.summary, idvar=sex, id='M')


&lt;/PRE&gt;</description>
      <pubDate>Thu, 28 Mar 2019 17:23:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/546964#M151516</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-28T17:23:46Z</dc:date>
    </item>
    <item>
      <title>Re: Write short code on top but run it in middle of a big code file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/546971#M151518</link>
      <description>&lt;P&gt;Oh I see.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let put it in a macro and call it later.&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 17:38:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/546971#M151518</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-03-28T17:38:56Z</dc:date>
    </item>
    <item>
      <title>Re: Write short code on top but run it in middle of a big code file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/546996#M151522</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/49486"&gt;@hhchenfx&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Oh I see.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let put it in a macro and call it later.&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That specific macro uses Keyword variable assigments. So if you like the default as assigned in the macro you do not need to pass a value for the parameter. For example I provided a default of ID for IDVAR but used in the example call a different variable because I created a different summary data set to demonstrate the flexibility. This one will only work with single values for the ID variable and I demonstrated how to use a character value. This will not work with multiple values though. You could pass a date value using id='01JAN2019'd.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2019 19:08:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/546996#M151522</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-03-28T19:08:26Z</dc:date>
    </item>
    <item>
      <title>Re: Write short code on top but run it in middle of a big code file</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/547077#M151548</link>
      <description>&lt;P&gt;Thanks for the note.&lt;/P&gt;
&lt;P&gt;It helps a lot.&lt;/P&gt;
&lt;P&gt;HHC&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 01:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-short-code-on-top-but-run-it-in-middle-of-a-big-code-file/m-p/547077#M151548</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2019-03-29T01:29:48Z</dc:date>
    </item>
  </channel>
</rss>

