<?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: Generating a report by using single SAS macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485943#M287145</link>
    <description>&lt;P&gt;The main problem is your macro is generating this condition in the WHERE clause&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;state=&amp;amp;state&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you pass in a value of&amp;nbsp;('CA','NY') then your macro will generate this syntax&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;state=('CA','NY')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is invalid.&lt;/P&gt;
&lt;P&gt;Change your code to use the IN operator and your call should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;state in (&amp;amp;state)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the extra () in your macro call is needed because you have a comma in the value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The extra () do not cause a problem for the IN operator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you could also just use a space instead of a comma between the values and then you would not need the () in the macro call.&amp;nbsp; The IN operator is just as happy to have a space delimited list as a comma delimited list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%profile (today= %sysfunc(today(),date9.), state='CA' 'NY', age=40, year=2016);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Aug 2018 20:41:23 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-08-10T20:41:23Z</dc:date>
    <item>
      <title>Generating a report by using single SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485606#M287137</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anyone help me find what is the mistake in the following code. Please find the attachment of requirements and data for creating this macro.&lt;/P&gt;&lt;P&gt;(I created this macro using SAS 9.4)&lt;/P&gt;&lt;P&gt;Thanks in advance.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro profile (today=, state=, age=, year=);
proc report data=profile nowd colwidth=10 spacing=5 headline headskip;
column Acct_ID Name Age Balance Last_Tran_Date ;
define Last_Tran_Date / format=ddmmyy10.;
compute before;
line @16 "title: Detail Listing Of Account" @68 "Run Date: &amp;amp;today ";
line @16 "state: &amp;amp;state " @45 "Age: &amp;lt;= &amp;amp;age " @68 "Tran_year: &amp;amp;year ";
line " ";
endcomp;
compute after; 
line 60* "_";
line @40 'total balance ='
balance.sum dollar6.;
endcomp;
where (age &amp;lt;= &amp;amp;age and year=&amp;amp;year) and state=&amp;amp;state;
run;
%mend;

%profile (today= %sysfunc(today(),date9.), state=('CA','NY'), age=40, year=2016);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 22:54:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485606#M287137</guid>
      <dc:creator>SN1</dc:creator>
      <dc:date>2018-08-09T22:54:05Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a report by using single SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485611#M287138</link>
      <description>&lt;P&gt;&lt;EM&gt;Step 1:&lt;/EM&gt; place the following command at the top of your program.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;EM&gt;Step 2: &lt;/EM&gt;run the code and see what errors show up in the SASLOG and see if you can figure out yourself what the problem is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;Step 3&lt;/EM&gt;: if you can't figure out what went wrong from the SASLOG, show us the SASLOG, by clicking on the {i} icon and pasting the SASLOG into the window that opens.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 22:03:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485611#M287138</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-09T22:03:54Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a report by using single SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485620#M287139</link>
      <description>&lt;P&gt;When i execute the code it is running perfectly.. but when i'm giving two values for state keyword the result is not as expected.&lt;/P&gt;&lt;P&gt;How should I correct it??&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Requirement-&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;selection criteria by &lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;State&lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;. &amp;nbsp;This should accommodate both “one state” as well as “multiple states”. You may define how the user specifies such a criterion in a reasonable way. If not specified then use all. &amp;nbsp;&amp;nbsp;&amp;nbsp;For example, user might specify this as&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;'CA' or&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;'CA','NY'&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 22:55:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485620#M287139</guid>
      <dc:creator>SN1</dc:creator>
      <dc:date>2018-08-09T22:55:44Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a report by using single SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485628#M287140</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223023"&gt;@SN1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;When i execute the code it is running perfectly.. but when i'm giving two values for state keyword the result is not as expected.&lt;/P&gt;
&lt;P&gt;How should I correct it??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Requirement-&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;selection criteria by &lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;State&lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;. &amp;nbsp;This should accommodate both “one state” as well as “multiple states”. You may define how the user specifies such a criterion in a reasonable way. If not specified then use all. &amp;nbsp;&amp;nbsp;&amp;nbsp;For example, user might specify this as&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;'CA' or&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;'CA','NY'&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The result of the call you show should generate an error about positional parameters.&lt;/P&gt;
&lt;P&gt;Hint: commas inside of parameters are very bad&lt;/P&gt;
&lt;P&gt;Second hint:&lt;/P&gt;
&lt;P&gt;Does this look correct to you?&lt;/P&gt;
&lt;P&gt;&lt;FONT face="SAS Monospace" size="2"&gt;where (age &amp;lt;= &lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;40&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt; and year=&lt;/FONT&gt;&lt;FONT color="#008080" face="SAS Monospace" size="2"&gt;2016&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;) and state=&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'CA'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="SAS Monospace" size="2"&gt;'NY'&lt;/FONT&gt;&lt;FONT face="SAS Monospace" size="2"&gt;;&lt;/FONT&gt; (It isn't).&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 23:48:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485628#M287140</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-09T23:48:57Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a report by using single SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485667#M287141</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223023"&gt;@SN1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;...&lt;BR /&gt;&lt;P&gt;Requirement-&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-weight: 400;"&gt;selection criteria by &lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;State&lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;. &amp;nbsp;This should accommodate both “one state” as well as “multiple states”. You may define how the user specifies such a criterion in a reasonable way. &lt;STRONG&gt;If not specified then use all&lt;/STRONG&gt;. &amp;nbsp;&amp;nbsp;&amp;nbsp;For example, user might specify this as&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;'CA' or&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-weight: 400;"&gt;'CA','NY'&lt;/SPAN&gt;&lt;/P&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;So you need to add code to the macro that creates a valid where statement incorporating that the user provides&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;one state&lt;/LI&gt;&lt;LI&gt;multiple states (don't just test with two states, try four)&lt;/LI&gt;&lt;LI&gt;no state, so that all states appear in the report&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;And, of course, you have to re-think the way multiple values are passed to the macro.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 06:24:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485667#M287141</guid>
      <dc:creator>error_prone</dc:creator>
      <dc:date>2018-08-10T06:24:45Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a report by using single SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485716#M287142</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223023"&gt;@SN1&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;When i execute the code it is running perfectly.. but when i'm giving two values for state keyword the result is not as expected.&lt;/P&gt;
&lt;P&gt;How should I correct it??&lt;/P&gt;
&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;This was never stated in the first message. You have to show us the problem. You have to provide enough details so we understand what the problem is.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So ... show us the problem, show us what you got and what you expected, so we can see what you are seeing.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 11:10:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485716#M287142</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-08-10T11:10:35Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a report by using single SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485857#M287143</link>
      <description>&lt;P&gt;I enhanced the code. when i executed the following code, its working fine if I did not give any values for 'state' but, the problem is if i give two values at a time for state (eg- i gave state='CA' or 'NY' , age=40, year=2016.) With the given values the output is showing the whole data in the dataset without filtering. If state= 'CA' and 'NY' the observations with 'CA' state are displayed excluding 'NY' values.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What i'm trying to do is i want a code which can handle both or multiple values or i can leave it like it's optional for 'state'.&lt;/P&gt;&lt;P&gt;the following code is working if i left it as optional..and if i give a single value but it is not showing the expected result. it is either taking all the observations or leaving the state value which is mentioned after 'and'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for detailed requirement please refer to the pdf document which I have attatched. It has a mockup and details.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is appreciated.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;BR /&gt;
%macro profile (today=, state=, age=, year=);
proc report data=profile nowd colwidth=10 spacing=5 headline headskip;
column Acct_ID Name Age Balance Last_Tran_Date ;
define Last_Tran_Date / format=ddmmyy10.;
compute before;
line @16 "title: Detail Listing Of Account" @68 "Run Date: &amp;amp;today ";
line @16 "state: &amp;amp;state " @45 "Age: &amp;lt;= &amp;amp;age " @68 "Tran_year: &amp;amp;year ";
line " ";
endcomp;
compute after; 
line 60* "_";
line @40 'total balance ='
balance.sum dollar6.;
endcomp;%if %length(&amp;amp;state)&amp;gt;0 %then %do;
where (age &amp;lt;= &amp;amp;age and year=&amp;amp;year) and state=&amp;amp;state;
%end;%else %do;where age &amp;lt;= &amp;amp;age and year=&amp;amp;year;%end;
run;
%mend;

%profile (today= %sysfunc(today(),date9.),  age=40, year=2016);


&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 16:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485857#M287143</guid>
      <dc:creator>SN1</dc:creator>
      <dc:date>2018-08-10T16:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a report by using single SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485939#M287144</link>
      <description>&lt;P&gt;BEFORE coding a macro you need to know what the valid SAS syntax is for any of the cases where you use the parameters.&lt;/P&gt;
&lt;P&gt;This statement indicates incorrect thinking as it is invalid SAS syntax.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;state='CA' or 'NY'&lt;/P&gt;
&lt;P&gt;SAS supplies an operator that will allow to test if a variable is any one of multiple values: IN&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;state in ('CA' 'NY')&amp;nbsp; no commas needed so don't put them in a macro parameter.&lt;/P&gt;
&lt;P&gt;The IN operator is also perfectly happy testing a single value&lt;/P&gt;
&lt;P&gt;state in ('CA')&lt;/P&gt;
&lt;P&gt;that should be a heavy enough clue stick though your state values must match exactly: "Ca" will not match "CA" so if there is doubt about the case of your variable you may consider:&lt;/P&gt;
&lt;P&gt;upcase(state) in ('CA' 'NY')&lt;/P&gt;
&lt;P&gt;The IN operator will also work with a list of numeric values such as&lt;/P&gt;
&lt;P&gt;year in (2014 2015 2018)&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 20:25:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485939#M287144</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-10T20:25:41Z</dc:date>
    </item>
    <item>
      <title>Re: Generating a report by using single SAS macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485943#M287145</link>
      <description>&lt;P&gt;The main problem is your macro is generating this condition in the WHERE clause&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;state=&amp;amp;state&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you pass in a value of&amp;nbsp;('CA','NY') then your macro will generate this syntax&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;state=('CA','NY')&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Which is invalid.&lt;/P&gt;
&lt;P&gt;Change your code to use the IN operator and your call should work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;state in (&amp;amp;state)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that the extra () in your macro call is needed because you have a comma in the value.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The extra () do not cause a problem for the IN operator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But you could also just use a space instead of a comma between the values and then you would not need the () in the macro call.&amp;nbsp; The IN operator is just as happy to have a space delimited list as a comma delimited list.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%profile (today= %sysfunc(today(),date9.), state='CA' 'NY', age=40, year=2016);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 20:41:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-a-report-by-using-single-SAS-macro/m-p/485943#M287145</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-08-10T20:41:23Z</dc:date>
    </item>
  </channel>
</rss>

