<?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 with Macro coding in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726807#M28149</link>
    <description>Thank you so much!</description>
    <pubDate>Tue, 16 Mar 2021 15:34:16 GMT</pubDate>
    <dc:creator>Tithi</dc:creator>
    <dc:date>2021-03-16T15:34:16Z</dc:date>
    <item>
      <title>Need help with Macro coding</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726525#M28132</link>
      <description>&lt;P&gt;I need to repeat a sas datastep using macro. I have two sets of dates, stimulant prescription dates "stim_1" to "stim_190" and opioid prescription dates "_1" to "_825".&amp;nbsp; I am interested to see if these prescriptions are concurrent prescriptions - if they are within 30 days of each other. So, I have written the following code to calculate:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data opi.concurrent_test;
set opi.concurrent_merged;

concurrent_1 = 0;

array bupe [825] _1 - _825;

if not missing (stim_1) then do i = 1 to 825;
concurrent_1 = (0 le (stim_1- bupe (i)) le 30);

if concurrent_1 = 1 then leave;
end;

drop i;

if (_1 - _825) | stim_1 = . then concurrent_1 = .;

if concurrent_1 = 1 then concurrent_1 = year(stim_1);

run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But now, I need to run this for all 190 stimulant dates. How can I write a macro to repeat this procedure 190 times.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 20:03:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726525#M28132</guid>
      <dc:creator>Tithi</dc:creator>
      <dc:date>2021-03-15T20:03:20Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Macro coding</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726530#M28133</link>
      <description>&lt;P&gt;I suspect your data structure is problematic here... can you please post example data?&lt;/P&gt;
&lt;P&gt;Fake data is fine. It would also help if you illustrated how you would do this for two drugs, even if it's entirely separate so we can see where the code needs to change.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some generic references to help you get started.&lt;/P&gt;
&lt;P&gt;UCLA introductory tutorial on macro variables and macros&lt;BR /&gt;&lt;A href="https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/" target="_blank"&gt;https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Tutorial on converting a working program to a macro&lt;BR /&gt;This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; &lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_blank"&gt;https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Examples of common macro usage&lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/326203"&gt;@Tithi&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I need to repeat a sas datastep using macro. I have two sets of dates, stimulant prescription dates "stim_1" to "stim_190" and opioid prescription dates "_1" to "_825".&amp;nbsp; I am interested to see if these prescriptions are concurrent prescriptions - if they are within 30 days of each other. So, I have written the following code to calculate:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data opi.concurrent_test;
set opi.concurrent_merged;

concurrent_1 = 0;

array bupe [825] _1 - _825;

if not missing (stim_1) then do i = 1 to 825;
concurrent_1 = (0 le (stim_1- bupe (i)) le 30);

if concurrent_1 = 1 then leave;
end;

drop i;

if (_1 - _825) | stim_1 = . then concurrent_1 = .;

if concurrent_1 = 1 then concurrent_1 = year(stim_1);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But now, I need to run this for all 190 stimulant dates. How can I write a macro to repeat this procedure 190 times.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 20:26:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726530#M28133</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-03-15T20:26:38Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Macro coding</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726532#M28134</link>
      <description>&lt;P&gt;You don't need macro. Just add another array for your&amp;nbsp;stimulant prescription dates and a second loop inside your first loop to process these.&lt;/P&gt;</description>
      <pubDate>Mon, 15 Mar 2021 20:27:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726532#M28134</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-03-15T20:27:56Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Macro coding</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726597#M28135</link>
      <description>I think I am struggling to write a second loop with a different dimension. Do you have an example? Thank you!</description>
      <pubDate>Tue, 16 Mar 2021 01:29:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726597#M28135</guid>
      <dc:creator>Tithi</dc:creator>
      <dc:date>2021-03-16T01:29:22Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Macro coding</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726598#M28136</link>
      <description>&lt;P&gt;Attached you will find a fake dataset. In my real dataset, I have 190 stimulant prescription date variables and 825 opioid prescription date variables over the course of 10 years. I need to subtract each stimulant prescription date with all the opioid prescription dates to find concurrent prescription. Please let me know if there is a better way to approach this coding. Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 01:46:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726598#M28136</guid>
      <dc:creator>Tithi</dc:creator>
      <dc:date>2021-03-16T01:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Macro coding</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726605#M28138</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data opi.concurrent_test;
set opi.concurrent_merged;

concurrent_1 = 0;

array bupe [825] _1 - _825;
array stims [*]  stim_1 - stim_100;
array concurrents [*]  concurrent_1 - concurrent_100;

do j = 1 to dim(stims);

if not missing (stims(j)) then do i = 1 to 825;
concurrents(j) = (0 le (stims(j) - bupe (i)) le 30);

if concurrents(j) = 1 then leave;
end;

end;
drop i;

if (_1 - _825) | stim_1 = . then concurrent_1 = .;

if concurrent_1 = 1 then concurrent_1 = year(stim_1);

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Something like the above.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Mar 2021 02:59:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726605#M28138</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2021-03-16T02:59:00Z</dc:date>
    </item>
    <item>
      <title>Re: Need help with Macro coding</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726807#M28149</link>
      <description>Thank you so much!</description>
      <pubDate>Tue, 16 Mar 2021 15:34:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Need-help-with-Macro-coding/m-p/726807#M28149</guid>
      <dc:creator>Tithi</dc:creator>
      <dc:date>2021-03-16T15:34:16Z</dc:date>
    </item>
  </channel>
</rss>

