<?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 a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728902#M226815</link>
    <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;Here is what I have tried so far. Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Profile;&lt;BR /&gt;input Acct_ID 1-4 Name $ 6-11 Birthday $ 13-21 Sex $ 23-24 State $ 25-26&lt;BR /&gt;Cust_Type $ 28-33 Product $ 35-42 Balance 44-47 Last_Tran_Date $ 49-57;&lt;BR /&gt;Cards;&lt;BR /&gt;1001 John 1/1/1962 M CA Gold Checking 1000 9/1/2015&lt;BR /&gt;1002 Mary 2/1/1972 F CA Silver Saving 2000 10/1/2015&lt;BR /&gt;1003 Peter 3/1/1982 M NY Gold Loan 3000 10/3/2016&lt;BR /&gt;1004 Mary 4/1/1992 F NY Silver Checking 4000 9/17/2016&lt;BR /&gt;1005 Linda 5/1/1994 F WA Gold Saving 5000&lt;BR /&gt;1006 Susan 6/1/1997 F WA Gold Loan 1000 9/15/2016&lt;BR /&gt;1007 Sam 7/1/1999 M CA Gold Checking 2000 2/1/2016&lt;BR /&gt;1008 Thomas 8/1/1962 M CA Silver Checking 3000 7/1/2016&lt;BR /&gt;1009 Linda 9/1/1982 F NY Silver Saving 4000&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data profile1;&lt;BR /&gt;set profile;&lt;BR /&gt;Birthday1 = input (Birthday, mmddyy10.);&lt;BR /&gt;Last_Tran_Date1 = input (Last_Tran_Date, mmddyy10.);&lt;BR /&gt;Tran_Year = year (Last_Tran_date1);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data profile2;&lt;BR /&gt;set profile1;&lt;BR /&gt;today = date();&lt;BR /&gt;days = today -birthday1;&lt;BR /&gt;age = floor (days/365);&lt;BR /&gt;drop today days birthday birthday1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*PROC PRINT--------------------------------------------------------------------------------------------------------------------------;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro final (title, state1 =, state2 =, age =, tran_year =, var = );&lt;/P&gt;&lt;P&gt;data profile3;&lt;BR /&gt;retain &amp;amp;var;&lt;BR /&gt;set profile2;&lt;BR /&gt;if tran_year ne .;&lt;BR /&gt;where age &amp;amp;age and Tran_Year = &amp;amp;Tran_year and (State = "&amp;amp;state1" or state = "&amp;amp;state2");&lt;BR /&gt;keep acct_ID Name Age Balance Last_Tran_Date tran_year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods rtf&lt;BR /&gt;file = "/folders/myfolders/macro.rtf";&lt;/P&gt;&lt;P&gt;proc sort data = profile3 out = profile4;&lt;BR /&gt;by tran_year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data = profile4 noobs sumlabel= "Total Balance" grandtotal_label= "Grand Total" width=uniformby;&lt;BR /&gt;by tran_year;&lt;BR /&gt;sum balance; *need macro for total balance&lt;BR /&gt;var &amp;amp;var;&lt;BR /&gt;title2 j=l "Title: &amp;amp;title" j=r Run date: "%sysfunc(date(),worddate.)";&lt;BR /&gt;title3 j=l "State: &amp;amp;state1, &amp;amp;state2" j=c "Age &amp;amp;age" j=r "Tran Year: &amp;amp;tran_year";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods rtf close;&lt;/P&gt;&lt;P&gt;%mend final;&lt;/P&gt;&lt;P&gt;%final (Detail Listing of Account, state1 = CA, state2 = NY, age &amp;lt;=40, tran_tear = 2016, Acct_ID Name Age Balance Last_Tran_Date);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Mar 2021 23:56:55 GMT</pubDate>
    <dc:creator>dmayurp</dc:creator>
    <dc:date>2021-03-24T23:56:55Z</dc:date>
    <item>
      <title>Write a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728662#M226714</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I want to write a macro that allows to specify:&lt;/P&gt;&lt;P&gt;1) Title of report (Listing of Account)&lt;/P&gt;&lt;P&gt;2) Variable to report (Acct_ID Name Age Balance Last_Tran_Date)&lt;/P&gt;&lt;P&gt;3) Whether a “Total Balance” (sum of balance) row is displayed&lt;/P&gt;&lt;P&gt;4) Selection criteria by state: “CA”, “NY”&lt;/P&gt;&lt;P&gt;5) Selection criteria by age: Age &amp;lt;=40&lt;/P&gt;&lt;P&gt;6) Selection criteria by year of Last_Tran_Date: 2016&lt;/P&gt;&lt;P&gt;- Additionally: all macro parameters should be optional. An omitted parameter should be interpreted to mean “ALL”&lt;/P&gt;&lt;P&gt;- please include a few representative example of how macro in invoked&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 03:06:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728662#M226714</guid>
      <dc:creator>dmayurp</dc:creator>
      <dc:date>2021-03-24T03:06:12Z</dc:date>
    </item>
    <item>
      <title>Re: Write a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728666#M226716</link>
      <description>&lt;P&gt;First of all, do you have a plain program before turning it into a macro?&lt;BR /&gt;If you can provide test data to go along with it, I think you will get a response.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 04:28:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728666#M226716</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-03-24T04:28:50Z</dc:date>
    </item>
    <item>
      <title>Re: Write a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728682#M226720</link>
      <description>&lt;P&gt;Step 1: have a working code without macro coding.&lt;/P&gt;
&lt;P&gt;Please post your report code, along with some example data (&lt;STRONG&gt;&lt;U&gt;&lt;EM&gt;in a data step with datalines&lt;/EM&gt;&lt;/U&gt;&lt;/STRONG&gt;). Include any TITLE and FOOTNOTE statements.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 08:17:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728682#M226720</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-24T08:17:49Z</dc:date>
    </item>
    <item>
      <title>Re: Write a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728902#M226815</link>
      <description>&lt;P&gt;HI,&lt;/P&gt;&lt;P&gt;Here is what I have tried so far. Thank you for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Profile;&lt;BR /&gt;input Acct_ID 1-4 Name $ 6-11 Birthday $ 13-21 Sex $ 23-24 State $ 25-26&lt;BR /&gt;Cust_Type $ 28-33 Product $ 35-42 Balance 44-47 Last_Tran_Date $ 49-57;&lt;BR /&gt;Cards;&lt;BR /&gt;1001 John 1/1/1962 M CA Gold Checking 1000 9/1/2015&lt;BR /&gt;1002 Mary 2/1/1972 F CA Silver Saving 2000 10/1/2015&lt;BR /&gt;1003 Peter 3/1/1982 M NY Gold Loan 3000 10/3/2016&lt;BR /&gt;1004 Mary 4/1/1992 F NY Silver Checking 4000 9/17/2016&lt;BR /&gt;1005 Linda 5/1/1994 F WA Gold Saving 5000&lt;BR /&gt;1006 Susan 6/1/1997 F WA Gold Loan 1000 9/15/2016&lt;BR /&gt;1007 Sam 7/1/1999 M CA Gold Checking 2000 2/1/2016&lt;BR /&gt;1008 Thomas 8/1/1962 M CA Silver Checking 3000 7/1/2016&lt;BR /&gt;1009 Linda 9/1/1982 F NY Silver Saving 4000&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data profile1;&lt;BR /&gt;set profile;&lt;BR /&gt;Birthday1 = input (Birthday, mmddyy10.);&lt;BR /&gt;Last_Tran_Date1 = input (Last_Tran_Date, mmddyy10.);&lt;BR /&gt;Tran_Year = year (Last_Tran_date1);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data profile2;&lt;BR /&gt;set profile1;&lt;BR /&gt;today = date();&lt;BR /&gt;days = today -birthday1;&lt;BR /&gt;age = floor (days/365);&lt;BR /&gt;drop today days birthday birthday1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*PROC PRINT--------------------------------------------------------------------------------------------------------------------------;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro final (title, state1 =, state2 =, age =, tran_year =, var = );&lt;/P&gt;&lt;P&gt;data profile3;&lt;BR /&gt;retain &amp;amp;var;&lt;BR /&gt;set profile2;&lt;BR /&gt;if tran_year ne .;&lt;BR /&gt;where age &amp;amp;age and Tran_Year = &amp;amp;Tran_year and (State = "&amp;amp;state1" or state = "&amp;amp;state2");&lt;BR /&gt;keep acct_ID Name Age Balance Last_Tran_Date tran_year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods rtf&lt;BR /&gt;file = "/folders/myfolders/macro.rtf";&lt;/P&gt;&lt;P&gt;proc sort data = profile3 out = profile4;&lt;BR /&gt;by tran_year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data = profile4 noobs sumlabel= "Total Balance" grandtotal_label= "Grand Total" width=uniformby;&lt;BR /&gt;by tran_year;&lt;BR /&gt;sum balance; *need macro for total balance&lt;BR /&gt;var &amp;amp;var;&lt;BR /&gt;title2 j=l "Title: &amp;amp;title" j=r Run date: "%sysfunc(date(),worddate.)";&lt;BR /&gt;title3 j=l "State: &amp;amp;state1, &amp;amp;state2" j=c "Age &amp;amp;age" j=r "Tran Year: &amp;amp;tran_year";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods rtf close;&lt;/P&gt;&lt;P&gt;%mend final;&lt;/P&gt;&lt;P&gt;%final (Detail Listing of Account, state1 = CA, state2 = NY, age &amp;lt;=40, tran_tear = 2016, Acct_ID Name Age Balance Last_Tran_Date);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 23:56:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728902#M226815</guid>
      <dc:creator>dmayurp</dc:creator>
      <dc:date>2021-03-24T23:56:55Z</dc:date>
    </item>
    <item>
      <title>Re: Write a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728903#M226816</link>
      <description>&lt;P&gt;Here is the data that I am working on it.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Profile;&lt;BR /&gt;input Acct_ID 1-4 Name $ 6-11 Birthday $ 13-21 Sex $ 23-24 State $ 25-26&lt;BR /&gt;Cust_Type $ 28-33 Product $ 35-42 Balance 44-47 Last_Tran_Date $ 49-57;&lt;BR /&gt;Cards;&lt;BR /&gt;1001 John 1/1/1962 M CA Gold Checking 1000 9/1/2015&lt;BR /&gt;1002 Mary 2/1/1972 F CA Silver Saving 2000 10/1/2015&lt;BR /&gt;1003 Peter 3/1/1982 M NY Gold Loan 3000 10/3/2016&lt;BR /&gt;1004 Mary 4/1/1992 F NY Silver Checking 4000 9/17/2016&lt;BR /&gt;1005 Linda 5/1/1994 F WA Gold Saving 5000&lt;BR /&gt;1006 Susan 6/1/1997 F WA Gold Loan 1000 9/15/2016&lt;BR /&gt;1007 Sam 7/1/1999 M CA Gold Checking 2000 2/1/2016&lt;BR /&gt;1008 Thomas 8/1/1962 M CA Silver Checking 3000 7/1/2016&lt;BR /&gt;1009 Linda 9/1/1982 F NY Silver Saving 4000&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data profile1;&lt;BR /&gt;set profile;&lt;BR /&gt;Birthday1 = input (Birthday, mmddyy10.);&lt;BR /&gt;Last_Tran_Date1 = input (Last_Tran_Date, mmddyy10.);&lt;BR /&gt;Tran_Year = year (Last_Tran_date1);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data profile2;&lt;BR /&gt;set profile1;&lt;BR /&gt;today = date();&lt;BR /&gt;days = today -birthday1;&lt;BR /&gt;age = floor (days/365);&lt;BR /&gt;drop today days birthday birthday1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;*PROC PRINT--------------------------------------------------------------------------------------------------------------------------;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro final (title, state1 =, state2 =, age =, tran_year =, var = );&lt;/P&gt;&lt;P&gt;data profile3;&lt;BR /&gt;retain &amp;amp;var;&lt;BR /&gt;set profile2;&lt;BR /&gt;if tran_year ne .;&lt;BR /&gt;where age &amp;amp;age and Tran_Year = &amp;amp;Tran_year and (State = "&amp;amp;state1" or state = "&amp;amp;state2");&lt;BR /&gt;keep acct_ID Name Age Balance Last_Tran_Date tran_year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods rtf&lt;BR /&gt;file = "/folders/myfolders/macro.rtf";&lt;/P&gt;&lt;P&gt;proc sort data = profile3 out = profile4;&lt;BR /&gt;by tran_year;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc print data = profile4 noobs sumlabel= "Total Balance" grandtotal_label= "Grand Total" width=uniformby;&lt;BR /&gt;by tran_year;&lt;BR /&gt;sum balance; *need macro for total balance&lt;BR /&gt;var &amp;amp;var;&lt;BR /&gt;title2 j=l "Title: &amp;amp;title" j=r Run date: "%sysfunc(date(),worddate.)";&lt;BR /&gt;title3 j=l "State: &amp;amp;state1, &amp;amp;state2" j=c "Age &amp;amp;age" j=r "Tran Year: &amp;amp;tran_year";&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;ods rtf close;&lt;/P&gt;&lt;P&gt;%mend final;&lt;/P&gt;&lt;P&gt;%final (Detail Listing of Account, state1 = CA, state2 = NY, age &amp;lt;=40, tran_tear = 2016, Acct_ID Name Age Balance Last_Tran_Date);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 23:58:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728903#M226816</guid>
      <dc:creator>dmayurp</dc:creator>
      <dc:date>2021-03-24T23:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Write a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728946#M226818</link>
      <description>&lt;P&gt;How about this code?&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;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro final (title=
             , state =
             , age =
             , tran_year =
             , var = 
             , sumvar = 
             );

data profile3;
  %if &amp;amp;var ne %then %do; /* I don't know if you need retain, but you can use empty parameters to make it work. */
  retain &amp;amp;var;
  %end;
  set profile2;
  if tran_year ne .;
  where %if &amp;amp;age ne  %then %do;
          age &amp;amp;age 
        %end;%else
        %do;
          age &amp;gt; 0
        %end;
        %if &amp;amp;Tran_Year ne  %then %do;
          and Tran_Year = &amp;amp;tran_year 
        %end;
        %if &amp;amp;State ne  %then %do;
          and (State in ("%sysfunc(TRANWRD(&amp;amp;state,%str(,)," "))"))
        %end;
        ;
  keep acct_ID Name Age Balance Last_Tran_Date tran_year;
run;

%if &amp;amp;title = %then %do;
  %let title=Detail Listing of Account;
%end;
%if &amp;amp;State =  %then %do;
  %let State=All;
%end;
%if &amp;amp;age =  %then %do;
  %let age=All;
%end;
%if &amp;amp;Tran_Year =  %then %do;
  %let tran_year=All;
%end;

ods rtf file = "/folders/myfolders/macro.rtf";

proc sort data = profile3 out = profile4;
  by tran_year;
run;

proc print data = profile4 noobs sumlabel= "Total Balance" grandtotal_label= "Grand Total" width=uniformby;
  by tran_year;
  %if %upcase(&amp;amp;sumvar)^=NO %then %do;
  sum balance; *need macro for total balance var &amp;amp;var;
  %end;
  title2 j=l "Title: &amp;amp;title" j=r "Run date: %sysfunc(date(),worddate.)";
  title3 j=l "State: &amp;amp;state" j=c "Age: &amp;amp;age" j=r "Tran Year: &amp;amp;tran_year";
run;

ods rtf close;

%mend final;

/* 2 sample patterns */
%final (title=Detail Listing of Account
       ,state =CA%str(,)NY
       ,age=%str(&amp;lt;=)40
       ,tran_year = 2016
       ,var=Acct_ID Name Age Balance Last_Tran_Date
       ,sumvar=yes
       );
%final (title=Detail Listing of Account
       ,state =
       ,age=
       ,tran_year = 
       ,var=
       ,sumvar=
       );&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 25 Mar 2021 02:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/728946#M226818</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-03-25T02:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Write a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/729248#M226913</link>
      <description>It worked. Thank you for your help.&lt;BR /&gt;</description>
      <pubDate>Thu, 25 Mar 2021 22:04:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/729248#M226913</guid>
      <dc:creator>dmayurp</dc:creator>
      <dc:date>2021-03-25T22:04:39Z</dc:date>
    </item>
    <item>
      <title>Re: Write a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/729250#M226915</link>
      <description>Thank you for your help</description>
      <pubDate>Thu, 25 Mar 2021 22:07:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Write-a-macro/m-p/729250#M226915</guid>
      <dc:creator>Aryyyan</dc:creator>
      <dc:date>2021-03-25T22:07:43Z</dc:date>
    </item>
  </channel>
</rss>

