<?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: Need help creating a MACRO in this situation in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Need-help-creating-a-MACRO-in-this-situation/m-p/253561#M6872</link>
    <description>&lt;P&gt;Not&amp;nbsp;knowing if you have any special considerations. Do you just want to learn macro programming?&lt;/P&gt;
&lt;P&gt;You have a quite&amp;nbsp;extensive program, so it's hard for me to tell you how to adopt it (in a wise way).&lt;/P&gt;
&lt;P&gt;Please see online doc, samples and there are hundreds of papers about&amp;nbsp;macro programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try to get started, and get back if you have a more specific question.&lt;/P&gt;</description>
    <pubDate>Tue, 01 Mar 2016 19:10:34 GMT</pubDate>
    <dc:creator>LinusH</dc:creator>
    <dc:date>2016-03-01T19:10:34Z</dc:date>
    <item>
      <title>Need help creating a MACRO in this situation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-help-creating-a-MACRO-in-this-situation/m-p/253551#M6870</link>
      <description>&lt;P&gt;Hi I would like to create a macro that would allow me to perform rougly the same procedure but with different datasets. Below are two datasets I would like to create a macro do in one step.Any help would be greatly appreciated&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;*&amp;lt;-STAT COL1 -&amp;gt; ASSIGN DEMOGRAPHICS TO &amp;gt;=1lab @facX;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;*&amp;gt;=1lab at Facility_X;&lt;/FONT&gt;&lt;BR /&gt;proc sort data=vs_Fac_pat; by cityno; run; */;&lt;BR /&gt;proc sort data=plwha; by cityno; run;&lt;BR /&gt;data Fac_demo;&lt;BR /&gt;merge vs_Fac_pat (in=a) plwha (in=b) ;&lt;BR /&gt;by cityno;&lt;BR /&gt;if a=1;&lt;BR /&gt;run; */Bright: 1493 Elm:1433;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=Fac_demo order=formatted;&lt;BR /&gt;Tables sex newrace livingage&amp;amp;year. risk/missing;&lt;BR /&gt;format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run; */COL1 ***;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*prepare col1 output;&lt;BR /&gt;proc freq data=Fac_demo order=formatted;&lt;BR /&gt;table sex /missing out=col1_sex (drop=percent);&lt;BR /&gt;table newrace /out=col1_race(drop=percent);&lt;BR /&gt;table livingage&amp;amp;year. /out=col1_age(drop=percent);&lt;BR /&gt;table risk /out=col1_risk(drop=percent);&lt;BR /&gt;format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=Fac_demo order=formatted;&lt;BR /&gt;table sex / out=col1_sex (drop=percent);&lt;BR /&gt;format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*prepare col1 output;&lt;BR /&gt;proc freq data=Fac_demo order=formatted;&lt;BR /&gt;table sex /out=col1_sex (drop=percent);&lt;BR /&gt;table newrace /out=col1_race(drop=percent);&lt;BR /&gt;table livingage&amp;amp;year. /out=col1_age(drop=percent);&lt;BR /&gt;table risk /out=col1_risk(drop=percent);&lt;BR /&gt;format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc transpose data=col1_sex out=col1_sex2; id sex; var count; run;&lt;BR /&gt;data col1_sex3 (drop = _LABEL_ _NAME_ ); set col1_sex2; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc transpose data=col1_race out=col1_race2; id newrace; var count; run;&lt;BR /&gt;data col1_race3 (drop = _LABEL_ _NAME_ ); set col1_race2; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc transpose data=col1_age out=col1_age2; id livingage&amp;amp;year.; var count; run;&lt;BR /&gt;data col1_age3 (drop = _LABEL_ _NAME_ ); set col1_age2; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc transpose data=col1_risk out=col1_risk2; id risk; var count; run;&lt;BR /&gt;data col1_risk3 (drop = _LABEL_ _NAME_ ); set col1_risk2; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data COL1_wf;&lt;BR /&gt;merge col1_sex3 col1_race3 col1_age3 col1_risk3 ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;*&amp;lt;-STAT COL2-&amp;gt; ASSIGN DEMOGRAPHICS TO RETAINED (&amp;gt;=2labs 3 mo apart) ;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#339966"&gt;*Retained;&lt;/FONT&gt;&lt;BR /&gt;proc sort data=InCare1_pat; by cityno; run; */ citynos;&lt;BR /&gt;proc sort data=plwha; by cityno; run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data InCare1_pat_demo;&lt;BR /&gt;merge InCare1_pat (in=a) plwha (in=b) ;&lt;BR /&gt;by cityno;&lt;BR /&gt;if a=1;&lt;BR /&gt;run; */Bright:1341 Elm: 1238;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc freq data=InCare1_pat_demo order=formatted;&lt;BR /&gt;Tables sex newrace livingage&amp;amp;year. risk;&lt;BR /&gt;format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run;*/COL2 ***;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*prepare col2 output;&lt;BR /&gt;proc freq data=InCare1_pat_demo order=formatted;&lt;BR /&gt;table sex /out=col2_sex (drop=percent);&lt;BR /&gt;table newrace /out=col2_race(drop=percent);&lt;BR /&gt;table livingage&amp;amp;year. /out=col2_age(drop=percent);&lt;BR /&gt;table risk /out=col2_risk(drop=percent);&lt;BR /&gt;format sex $newsex. newrace $race5cat. livingage&amp;amp;year. newage. risk $newrisk.;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc transpose data=col2_sex out=col2_sex2; id sex; var count; run;&lt;BR /&gt;data col2_sex3 (drop = _LABEL_ _NAME_ ); set col2_sex2; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc transpose data=col2_race out=col2_race2; id newrace; var count; run;&lt;BR /&gt;data col2_race3 (drop = _LABEL_ _NAME_ ); set col2_race2; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc transpose data=col2_age out=col2_age2; id livingage&amp;amp;year.; var count; run;&lt;BR /&gt;data col2_age3 (drop = _LABEL_ _NAME_ ); set col2_age2; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc transpose data=col2_risk out=col2_risk2; id risk; var count; run;&lt;BR /&gt;data col2_risk3 (drop = _LABEL_ _NAME_ ); set col2_risk2; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data COL2_wf;&lt;BR /&gt;merge col2_sex3 col2_race3 col2_age3 col2_risk3 ;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2016 18:43:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-help-creating-a-MACRO-in-this-situation/m-p/253551#M6870</guid>
      <dc:creator>beverlyobeng</dc:creator>
      <dc:date>2016-03-01T18:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need help creating a MACRO in this situation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-help-creating-a-MACRO-in-this-situation/m-p/253560#M6871</link>
      <description>&lt;P&gt;Are you asking how to repeat all of that code for different tables?&lt;/P&gt;
&lt;P&gt;Or how to modify that code?&lt;/P&gt;
&lt;P&gt;I'm not sure where macro's come in or what exactly you need help with....&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2016 19:09:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-help-creating-a-MACRO-in-this-situation/m-p/253560#M6871</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-01T19:09:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need help creating a MACRO in this situation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-help-creating-a-MACRO-in-this-situation/m-p/253561#M6872</link>
      <description>&lt;P&gt;Not&amp;nbsp;knowing if you have any special considerations. Do you just want to learn macro programming?&lt;/P&gt;
&lt;P&gt;You have a quite&amp;nbsp;extensive program, so it's hard for me to tell you how to adopt it (in a wise way).&lt;/P&gt;
&lt;P&gt;Please see online doc, samples and there are hundreds of papers about&amp;nbsp;macro programming.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try to get started, and get back if you have a more specific question.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Mar 2016 19:10:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-help-creating-a-MACRO-in-this-situation/m-p/253561#M6872</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2016-03-01T19:10:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need help creating a MACRO in this situation</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Need-help-creating-a-MACRO-in-this-situation/m-p/253562#M6873</link>
      <description>&lt;P&gt;I just posted this and I think it applies here as well. In your case I would also recommend another step - at the end of your macro you may want to remove any temporary data sets so they're not around for another macro iteration.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;EM&gt;&lt;CODE class=" language-sas"&gt;Wrap your code in %macro/%mend and assign a name, eg:&lt;/CODE&gt;&lt;/EM&gt;&lt;/LI&gt;
&lt;LI&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro summarize;

*your sas code;

%mend;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Test that it works by calling it.&amp;nbsp;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%summarize;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Change macro to use a parameter &amp;nbsp;- the parameter is called dataset, and changes for each dataset you'd like to process
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro summarize(dataset);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Change variable name in code to be parameter value, eg:
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=&amp;amp;dataset;
...
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Test again&amp;nbsp;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%summarize(bpchild);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Make sure it works for multiple cases.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Tue, 01 Mar 2016 19:11:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Need-help-creating-a-MACRO-in-this-situation/m-p/253562#M6873</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-03-01T19:11:55Z</dc:date>
    </item>
  </channel>
</rss>

