<?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 Reg Conditions inside Macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Reg-Conditions-inside-Macro/m-p/157227#M262978</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;I have a sas code and interested to put inside a macro because I have to repeat the same for every month.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;I added the %macro at the top and %mend statements at the bottom as shown???&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;each time I run the code the last datastep produces two datasets for every month.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;The input dataset is the same every time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt; About IF ststements inside of macro.......Do I need to add % sign before the conditions or leave as it is as shown below???&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;&lt;STRONG&gt;%macro PSI90 (bgndt=,enddt=,period=);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want1;&lt;/P&gt;&lt;P&gt;set have;&lt;BR /&gt; where DateDischargeKey between &amp;amp;bgndt and &amp;amp;enddt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*SOME DATA STEP CODE ........ FORMATS......PROC FREQS .......etc etc*/&lt;/P&gt;&lt;P&gt;/*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****/&lt;/P&gt;&lt;P&gt;data location;&lt;BR /&gt;set want1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data final(drop=GenderKey gender_name Abbr Ethnic_Group FinancialClassKey)&lt;BR /&gt;set location;&lt;BR /&gt;if ATYPE=4 then POINTOFORIGINUB04=put(Admit_Source_Code,$PorignB.);&lt;/P&gt;&lt;P&gt;if AgeAtAdmission=0 and intck('year',Birth_Date2,ADMIT_DATE1) ge 1 then AgeAtAdmission=intck('year',Birth_Date2,ADMIT_DATE1,'c');&lt;BR /&gt;if intck('year',Birth_Date2,ADMIT_DATE1) lt 1 then AGEDAY=ADMIT_DATE1-Birth_Date2;&lt;BR /&gt;if AGEDAY ge 365 then delete;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname PSI "C:\AHRQQI";&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000; font-size: 12pt;"&gt;data psi.allpayer_&amp;amp;period.&lt;/SPAN&gt;(drop=Birth_Date2 DISCH_DATE1 ADMIT_DATE1 Row_Source Financial_Class DischargeDispositionID disposition_name&lt;BR /&gt;rename=(AgeAtAdmission=age HospitalAccountID=Key LengthOfStay=LOS))&lt;BR /&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;psi.medicare_&amp;amp;period.&lt;/SPAN&gt;(drop=Birth_Date2 DISCH_DATE1 ADMIT_DATE1 Row_Source Financial_Class DischargeDispositionID disposition_name&lt;BR /&gt;rename=(AgeAtAdmission=age HospitalAccountID=Key LengthOfStay=LOS));&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;set final;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;output psi.allpayer_&amp;amp;period.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;if financial_class='Medicare' then output psi.medicare_&amp;amp;period.;&lt;/SPAN&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;%mend PSI90;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%PSI90 (bgndt=20130101,enddt=20130131,period=JAN2013_JAN2013);&amp;nbsp; &lt;BR /&gt;%PSI90 (bgndt=20130201,enddt=20130228,period=FEB2013_FEB2013);&amp;nbsp; &lt;BR /&gt;%PSI90 (bgndt=20130301,enddt=20130331,period=MAR2013_MAR2013);&lt;BR /&gt;%PSI90 (bgndt=20130401,enddt=20130430,period=APR2013_APR2013);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 05 Nov 2014 11:49:39 GMT</pubDate>
    <dc:creator>robertrao</dc:creator>
    <dc:date>2014-11-05T11:49:39Z</dc:date>
    <item>
      <title>Reg Conditions inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reg-Conditions-inside-Macro/m-p/157227#M262978</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Hi,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;I have a sas code and interested to put inside a macro because I have to repeat the same for every month.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;I added the %macro at the top and %mend statements at the bottom as shown???&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;each time I run the code the last datastep produces two datasets for every month.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;The input dataset is the same every time.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt; About IF ststements inside of macro.......Do I need to add % sign before the conditions or leave as it is as shown below???&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12pt;"&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;&lt;STRONG&gt;%macro PSI90 (bgndt=,enddt=,period=);&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want1;&lt;/P&gt;&lt;P&gt;set have;&lt;BR /&gt; where DateDischargeKey between &amp;amp;bgndt and &amp;amp;enddt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;/*SOME DATA STEP CODE ........ FORMATS......PROC FREQS .......etc etc*/&lt;/P&gt;&lt;P&gt;/*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****&lt;BR /&gt;*****/&lt;/P&gt;&lt;P&gt;data location;&lt;BR /&gt;set want1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data final(drop=GenderKey gender_name Abbr Ethnic_Group FinancialClassKey)&lt;BR /&gt;set location;&lt;BR /&gt;if ATYPE=4 then POINTOFORIGINUB04=put(Admit_Source_Code,$PorignB.);&lt;/P&gt;&lt;P&gt;if AgeAtAdmission=0 and intck('year',Birth_Date2,ADMIT_DATE1) ge 1 then AgeAtAdmission=intck('year',Birth_Date2,ADMIT_DATE1,'c');&lt;BR /&gt;if intck('year',Birth_Date2,ADMIT_DATE1) lt 1 then AGEDAY=ADMIT_DATE1-Birth_Date2;&lt;BR /&gt;if AGEDAY ge 365 then delete;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;libname PSI "C:\AHRQQI";&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN style="color: #ff0000; font-size: 12pt;"&gt;data psi.allpayer_&amp;amp;period.&lt;/SPAN&gt;(drop=Birth_Date2 DISCH_DATE1 ADMIT_DATE1 Row_Source Financial_Class DischargeDispositionID disposition_name&lt;BR /&gt;rename=(AgeAtAdmission=age HospitalAccountID=Key LengthOfStay=LOS))&lt;BR /&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;psi.medicare_&amp;amp;period.&lt;/SPAN&gt;(drop=Birth_Date2 DISCH_DATE1 ADMIT_DATE1 Row_Source Financial_Class DischargeDispositionID disposition_name&lt;BR /&gt;rename=(AgeAtAdmission=age HospitalAccountID=Key LengthOfStay=LOS));&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;set final;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;output psi.allpayer_&amp;amp;period.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;if financial_class='Medicare' then output psi.medicare_&amp;amp;period.;&lt;/SPAN&gt;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 14pt;"&gt;%mend PSI90;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%PSI90 (bgndt=20130101,enddt=20130131,period=JAN2013_JAN2013);&amp;nbsp; &lt;BR /&gt;%PSI90 (bgndt=20130201,enddt=20130228,period=FEB2013_FEB2013);&amp;nbsp; &lt;BR /&gt;%PSI90 (bgndt=20130301,enddt=20130331,period=MAR2013_MAR2013);&lt;BR /&gt;%PSI90 (bgndt=20130401,enddt=20130430,period=APR2013_APR2013);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Nov 2014 11:49:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reg-Conditions-inside-Macro/m-p/157227#M262978</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2014-11-05T11:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reg Conditions inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reg-Conditions-inside-Macro/m-p/157228#M262979</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It should be ok, assuming your logic is what you want.&amp;nbsp; The simplest way to think about the macro pre-processor is that of a text replace/generate function.&amp;nbsp; So in your example above, take a copy of the macro.&amp;nbsp; Now go through line by line and replace the parameters with their values.&amp;nbsp; Is the code how you would expect to see it if you just wanted to run it once?&amp;nbsp; If so then your good to go.&lt;/P&gt;&lt;P&gt;The %if syntax (along with %do and some other items), is to conditionally generate code.&amp;nbsp; In your example you are checking a variable within a datastep and directing that data to an output dataset depending on the value, so you want to keep this code as datastep code. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Nov 2014 11:58:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reg-Conditions-inside-Macro/m-p/157228#M262979</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-11-05T11:58:58Z</dc:date>
    </item>
    <item>
      <title>Re: Reg Conditions inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reg-Conditions-inside-Macro/m-p/157229#M262980</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for the reply RW9...&lt;/P&gt;&lt;P&gt;What is the meaning of "Conditionally generating code"???&lt;/P&gt;&lt;P&gt;secondly, I have a couple of conditions in the last but one dataset also .(as shown above)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thnx&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Nov 2014 12:09:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reg-Conditions-inside-Macro/m-p/157229#M262980</guid>
      <dc:creator>robertrao</dc:creator>
      <dc:date>2014-11-05T12:09:19Z</dc:date>
    </item>
    <item>
      <title>Re: Reg Conditions inside Macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Reg-Conditions-inside-Macro/m-p/157230#M262981</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Well, conditional - take an example:&lt;/P&gt;&lt;P&gt;%macro Test (Print_Hello_World=No);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %if "&amp;amp;Print_hello_World."="Yes" %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc report data=hello_world_dataset;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; proc report data=sashelp.class;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%mend Test;&lt;/P&gt;&lt;P&gt;%Test (Print_Hello_World=Yes);&lt;/P&gt;&lt;P&gt;%Test ();&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now in the first call the macro variable=Yes.&amp;nbsp; The %if statement is evaluated as true and the proc report for the hello_world_dataset is generated and sent off to be run, the other proc report does not get generated. &lt;/P&gt;&lt;P&gt;In the second call the default of No is used, hence the if statement evaluates as false and the first proc report never gets generated.&amp;nbsp; The second one does.&lt;/P&gt;&lt;P&gt;So based of the %if statement result one or the other proc reports are sent to be run from the macro pre-processor, hence you generate code conditionally based on your parameters in this instance.&amp;nbsp; %do is similar, however when encountered it repeats the code within the block for each iteration, so again generating code programmatically.&lt;/P&gt;&lt;P&gt;You can also do this whole process through datastep which is something I do a fair bit, using the call execute, e.g. the above macro could be written:&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; do I='Y','';&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if I='Y' then call execute('proc report data=hello_world_dataset; run;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else call execute('proc report dataset=sashelp.class; run;');&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 05 Nov 2014 12:57:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Reg-Conditions-inside-Macro/m-p/157230#M262981</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-11-05T12:57:02Z</dc:date>
    </item>
  </channel>
</rss>

