<?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 Take code out of macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Take-code-out-of-macro/m-p/371965#M275947</link>
    <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;Please help take below code out of macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to select certain disease cases from the data &amp;amp;file&amp;amp;year if found in the list &amp;amp;steps. Macros defined in the code below. I don't need double logics in macro as is now because&amp;nbsp;I have a physical file prepped to replace&amp;nbsp;&lt;SPAN&gt;&amp;amp;file&amp;amp;year now. I commented out the parts that I thought would not need. But it did not work out. I really have to get it out tonight. Crossing my fingers if anybody there for help.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data icd(drop=diag rename=x=icd); set icd;
 format x $10.;
  diag=compress(diag,'.');
  diag_original=diag;
 x="[*]"||diag;
run;

proc sql noprint;
   select  icd
     into :steps separated by '|'
     from  icd;
quit;

%put &amp;amp;steps;

options compress=yes;
%let x=:Code_1 - :Code_24;

/*****************************************************************************************************************/;
libname red "C:\;&lt;BR /&gt;
%macro loop(case);

%global case1;
%let case1=&amp;amp;case;

%if &amp;amp;case=shape                        %then %let condition = &amp;amp;steps;

proc datasets noprint;
 delete all_&amp;amp;type._other;
run;
 
/*%do year = 2014 %to 2017; */
/*%if &amp;amp;year &amp;gt;= 2016 %then */
/*  %do; */
/*    libname red "C:...";*/
/*     %if &amp;amp;type=Int %then %let file=&amp;amp;type.;*/
/*	  %else;*/
/*     %if &amp;amp;type=Out %then %let file=&amp;amp;type._direct;*/
/*   %end; */

data momentary(compress=yes); set red.&amp;amp;file&amp;amp;year(where=(patient_county_code in (58,33,37)));
icd_code = catx('*','*',Diag_Code, of Code:); 

if prxmatch("m/&amp;amp;condition/oi",icd_code) &amp;gt; 0; 
source="In";
run;

proc append base=all_&amp;amp;type._other(compress=yes) data=momentary force;
run;

%end;

%mend loop;

/*%let type=Int;/*
%loop(shape);

/*%let type=Out;/&lt;BR /&gt;%loop(shape);*
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jun 2017 20:38:33 GMT</pubDate>
    <dc:creator>Cruise</dc:creator>
    <dc:date>2017-06-30T20:38:33Z</dc:date>
    <item>
      <title>Take code out of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Take-code-out-of-macro/m-p/371965#M275947</link>
      <description>&lt;P&gt;Hi guys,&lt;/P&gt;&lt;P&gt;Please help take below code out of macro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to select certain disease cases from the data &amp;amp;file&amp;amp;year if found in the list &amp;amp;steps. Macros defined in the code below. I don't need double logics in macro as is now because&amp;nbsp;I have a physical file prepped to replace&amp;nbsp;&lt;SPAN&gt;&amp;amp;file&amp;amp;year now. I commented out the parts that I thought would not need. But it did not work out. I really have to get it out tonight. Crossing my fingers if anybody there for help.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data icd(drop=diag rename=x=icd); set icd;
 format x $10.;
  diag=compress(diag,'.');
  diag_original=diag;
 x="[*]"||diag;
run;

proc sql noprint;
   select  icd
     into :steps separated by '|'
     from  icd;
quit;

%put &amp;amp;steps;

options compress=yes;
%let x=:Code_1 - :Code_24;

/*****************************************************************************************************************/;
libname red "C:\;&lt;BR /&gt;
%macro loop(case);

%global case1;
%let case1=&amp;amp;case;

%if &amp;amp;case=shape                        %then %let condition = &amp;amp;steps;

proc datasets noprint;
 delete all_&amp;amp;type._other;
run;
 
/*%do year = 2014 %to 2017; */
/*%if &amp;amp;year &amp;gt;= 2016 %then */
/*  %do; */
/*    libname red "C:...";*/
/*     %if &amp;amp;type=Int %then %let file=&amp;amp;type.;*/
/*	  %else;*/
/*     %if &amp;amp;type=Out %then %let file=&amp;amp;type._direct;*/
/*   %end; */

data momentary(compress=yes); set red.&amp;amp;file&amp;amp;year(where=(patient_county_code in (58,33,37)));
icd_code = catx('*','*',Diag_Code, of Code:); 

if prxmatch("m/&amp;amp;condition/oi",icd_code) &amp;gt; 0; 
source="In";
run;

proc append base=all_&amp;amp;type._other(compress=yes) data=momentary force;
run;

%end;

%mend loop;

/*%let type=Int;/*
%loop(shape);

/*%let type=Out;/&lt;BR /&gt;%loop(shape);*
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 20:38:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Take-code-out-of-macro/m-p/371965#M275947</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-06-30T20:38:33Z</dc:date>
    </item>
    <item>
      <title>Re: Take code out of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Take-code-out-of-macro/m-p/371994#M275948</link>
      <description>&lt;P&gt;you could pull the code from macro i.e., you could get the resolved code into the sas file with the following code. You should run the code with a macro call as below and a sample.sas file will be created in the path you specified. &lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename mprint '~path/sample.sas';
options mfile mprint;
%loop(defects);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 30 Jun 2017 05:29:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Take-code-out-of-macro/m-p/371994#M275948</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-06-30T05:29:45Z</dc:date>
    </item>
    <item>
      <title>Re: Take code out of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Take-code-out-of-macro/m-p/372274#M275949</link>
      <description>&lt;P&gt;"But it did not work out." is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the {i} to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output? Provide input data in the form of a dataset, the actual results and the expected results. Data should be in the form of a data step. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat&lt;/A&gt;... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;With macros run the code with Options Mprint Symbolgen Mlogic; before posting the log.&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2017 18:10:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Take-code-out-of-macro/m-p/372274#M275949</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-06-30T18:10:05Z</dc:date>
    </item>
    <item>
      <title>Re: Take code out of macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Take-code-out-of-macro/m-p/372294#M275950</link>
      <description>Studying basics of dynamic programming. Starting with this SUGI paper: &lt;A href="http://support.sas.com/resources/papers/proceedings11/113-2011.pdf" target="_blank"&gt;http://support.sas.com/resources/papers/proceedings11/113-2011.pdf&lt;/A&gt;. Let me know if you suggest better resources for novice in macro like me. Thanks Ballardw.</description>
      <pubDate>Fri, 30 Jun 2017 19:55:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Take-code-out-of-macro/m-p/372294#M275950</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-06-30T19:55:20Z</dc:date>
    </item>
  </channel>
</rss>

