<?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: Creating a macro and applying a loop but it's failing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-and-applying-a-loop-but-it-s-failing/m-p/955574#M373185</link>
    <description>&lt;P&gt;Didn't we already figure this out on your first posting?&lt;/P&gt;
&lt;P&gt;You have a statement comment in the code that was missing its semicolon. That turned one of the DO statements into part of the comment.&amp;nbsp; Hence you ended up with an extra END statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Troubleshooting-a-Macro-Error-Resolving-No-Matching-DO-SELECT/td-p/955486/jump-to/first-unread-message" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Troubleshooting-a-Macro-Error-Resolving-No-Matching-DO-SELECT/td-p/955486/jump-to/first-unread-message&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 09 Jan 2025 00:57:37 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2025-01-09T00:57:37Z</dc:date>
    <item>
      <title>Creating a macro and applying a loop but it's failing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-and-applying-a-loop-but-it-s-failing/m-p/955482#M373155</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have a block of code that is quite repetitive, as it processes similar tasks across multiple datasets. To streamline this, I’m trying to create a macro, &lt;CODE&gt;medpar_analysis&lt;/CODE&gt;, to loop through the dataset &lt;CODE&gt;medpar&lt;/CODE&gt; for the years 2019 to 2021.&lt;/P&gt;&lt;P&gt;However, when I run the macro, I encounter the following error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR 161-185: No matching DO/SELECT statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The error points to a specific line of code within the macro. Interestingly, when I run the same code for an individual dataset (e.g., &lt;CODE&gt;medpar_2019&lt;/CODE&gt;), it compiles and executes without any issues. This leads me to believe the issue lies in how the macro handles loops or iterates over the datasets.&lt;/P&gt;&lt;P&gt;I’m unsure where the unmatched &lt;CODE&gt;DO&lt;/CODE&gt; loop or &lt;CODE&gt;SELECT&lt;/CODE&gt; statement might be causing the error. Could you help identify the problem and suggest a solution?&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;"127 0; if strip(DGNS[i]) in PSYCH_CODES then ALZH_MEDPAR = 0; if strip(DGNS[i]) in&lt;BR /&gt;127 ! OUD_CODES then ALZH_MEDPAR = 0; end; end; do i = 1 to dim(DGNS); if&lt;BR /&gt;---&lt;BR /&gt;161&lt;BR /&gt;127 ! missing(ALZH_MEDPAR) then do; if missing(DGNS[i]) then ALZH_MEDPAR ="&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro medpar_analysis;&lt;BR /&gt;%do years=2019 %to 2021;&lt;/P&gt;&lt;P&gt;data output.merged_medpar_mbsf_pdpn_&amp;amp;years._1;&lt;BR /&gt;set output.merged_medpar_mbsf_pdpn_&amp;amp;years._1;&lt;BR /&gt;array DGNS[25] $ DGNS_1_CD -- DGNS_25_CD;&lt;BR /&gt;DEPRESSION_MEDPAR = .;&lt;BR /&gt;NONALZH_DEMEN_MEDPAR = .;&lt;BR /&gt;ALZH_MEDPAR = .;&lt;BR /&gt;PNEUMO_MEDPAR = .;&lt;BR /&gt;hf_medpar =.;&lt;BR /&gt;PRKNSN_MEDPAR = .;&lt;BR /&gt;STROKE_TIA_MEDPAR = .;&lt;BR /&gt;ANXI_MEDICARE_MEDPAR =.;&lt;BR /&gt;BIPOLAR_MEDPAR = .;&lt;BR /&gt;TBI_MEDPAR = .;&lt;BR /&gt;DRUGS_MEDPAR = .;&lt;BR /&gt;SCHIOT_MEDPAR = .;&lt;BR /&gt;OUD_ANY_MEDPAR = .;&lt;/P&gt;&lt;P&gt;array depression_codes[50] $8 _temporary_ ('F0631', 'F0632', 'F310', 'F3110', 'F3111', 'F3112', 'F3113',&lt;BR /&gt;'F312', 'F3130', 'F3131', 'F3132', 'F314', 'F315', 'F3160',&lt;BR /&gt;'F3161', 'F3162', 'F3163', 'F3164', 'F3171', 'F3173', 'F3175',&lt;BR /&gt;'F3176', 'F3177', 'F3178', 'F3181', 'F3189', 'F319', 'F320',&lt;BR /&gt;'F321', 'F322', 'F323', 'F324', 'F325', 'F328', 'F3289',&lt;BR /&gt;'F329', 'F32A', 'F330', 'F331', 'F332', 'F333', 'F3340',&lt;BR /&gt;'F3341', 'F3342', 'F338', 'F339', 'F340', 'F341', 'F4321', 'F4323');&lt;/P&gt;&lt;P&gt;array nonalzhimers_codes[84] $8 _temporary_ ('F0150', 'F0151', 'F01511', 'F01518', 'F0152', 'F0153', 'F0154',&lt;BR /&gt;'F01A0', 'F01A11', 'F01A18', 'F01A2', 'F01A3', 'F01A4', 'F01B0',&lt;BR /&gt;'F01B11', 'F01B18', 'F01B2', 'F01B3', 'F01B4', 'F01C0', 'F01C11',&lt;BR /&gt;'F01C18', 'F01C2', 'F01C3', 'F01C4', 'F0280', 'F0281', 'F02811',&lt;BR /&gt;'F02818', 'F0282', 'F0283', 'F0284', 'F02A0', 'F02A11', 'F02A18',&lt;BR /&gt;'F02A2', 'F02A3', 'F02A4', 'F02B0', 'F02B11', 'F02B18', 'F02B2',&lt;BR /&gt;'F02B3', 'F02B4', 'F02C0', 'F02C11', 'F02C18', 'F02C2', 'F02C3',&lt;BR /&gt;'F02C4', 'F0390', 'F0391', 'F03911', 'F03918', 'F0392', 'F0393',&lt;BR /&gt;'F0394', 'F03A0', 'F03A11', 'F03A18', 'F03A2', 'F03A3', 'F03A4',&lt;BR /&gt;'F03B0', 'F03B11', 'F03B18', 'F03B2', 'F03B3', 'F03B4', 'F03C0',&lt;BR /&gt;'F03C11', 'F03C18', 'F03C2', 'F03C3', 'F03C4', 'F05', 'G138',&lt;BR /&gt;'G3101', 'G3109', 'G311', 'G312', 'G3183', 'G94', 'R4181');&lt;/P&gt;&lt;P&gt;array alzhimers_codes[4] $8 _temporary_ ('G300', 'G301','G308', 'G309');&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;do i = 1 to dim(DGNS);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if not missing(DGNS[i])then do;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS[i]) in depression_codes then DEPRESSION_MEDPAR=1;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* this part of the code will an a 0 to the depression indicator if there are any diagnosis codes*/&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;do i = 1 to dim(DGNS);&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if missing(DEPRESSION_MEDPAR) then do;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if strip(DGNS[i]) in nonalzhimers_codes then DEPRESSION_MEDPAR =0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in alzhimers_codes then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in pneumonia_codes then DEPRESSION_MEDPAR= 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in hf_codes then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in prknsn_codes then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in stroke_codes then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in stroke_exclusion_codes then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in anxiety_codes then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in bipolar_codes then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in TBI_codes then DEPRESSION_MEDPAR = 0;&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in DRUG_USE_CODES then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in PSYCH_CODES then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in OUD_CODES then DEPRESSION_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;*assigning -9 to missing DGNS values;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;do i = 1 to dim(DGNS);&lt;/DIV&gt;&lt;DIV&gt;if missing(DEPRESSION_MEDPAR) then do;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if missing(DGNS[i]) then DEPRESSION_MEDPAR =-9;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;*&lt;/DIV&gt;&lt;DIV&gt;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* verifying*/&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;indicator1 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator2 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator3 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator4 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator5 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator6 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator7 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator8 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator9 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator10 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator11 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator12 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator13 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator14 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator15 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator16 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator17 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator18 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator19 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator20 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator21 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator22 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator23 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator24 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator25 = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; indicator_all = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_1_CD) in depression_codes then indicator1 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_2_CD) in depression_codes then indicator2 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_3_CD) in depression_codes then indicator3 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_4_CD) in depression_codes then indicator4 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_5_CD) in depression_codes then indicator5 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_6_CD) in depression_codes then indicator6 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_7_CD) in depression_codes then indicator7 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_8_CD) in depression_codes then indicator8 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_9_CD) in depression_codes then indicator9 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_10_CD) in depression_codes then indicator10 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_11_CD) in depression_codes then indicator11 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_12_CD) in depression_codes then indicator12 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_13_CD) in depression_codes then indicator13 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_14_CD) in depression_codes then indicator14 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_15_CD) in depression_codes then indicator15 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_16_CD) in depression_codes then indicator16 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_17_CD) in depression_codes then indicator17 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_18_CD) in depression_codes then indicator18 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_19_CD) in depression_codes then indicator19 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_20_CD) in depression_codes then indicator20 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_21_CD) in depression_codes then indicator21 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_22_CD) in depression_codes then indicator22 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_23_CD) in depression_codes then indicator23 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_24_CD) in depression_codes then indicator24 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_25_CD) in depression_codes then indicator25 = 1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;indicator_count=sum(of indicator1-indicator25);&lt;/DIV&gt;&lt;DIV&gt;if indicator_count &amp;gt; 0 then indicator_all = 1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/****************************************************/&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Nonalzhimers_MEDPAR*/&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;*this part of the code will assign a 1 to any depression codes;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;do i = 1 to dim(DGNS);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if not missing(DGNS[i])then do;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS[i]) in nonalzhimers_codes then NONALZH_DEMEN_MEDPAR=1;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* this part of the code will an a 0 to the depression indicator if there are any diagnosis codes*/&lt;/DIV&gt;&lt;DIV&gt;do i = 1 to dim(DGNS);&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if missing(NONALZH_DEMEN_MEDPAR) then do;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS[i]) in depression_codes then NONALZH_DEMEN_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS[i]) in alzhimers_codes then NONALZH_DEMEN_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in pneumonia_codes then NONALZH_DEMEN_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in hf_codes then NONALZH_DEMEN_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in prknsn_codes then NONALZH_DEMEN_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in stroke_codes then NONALZH_DEMEN_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in stroke_exclusion_codes then NONALZH_DEMEN_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in anxiety_codes then NONALZH_DEMEN_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in bipolar_codes then NONALZH_DEMEN_MEDPAR = 0;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in TBI_codes then NONALZH_DEMEN_MEDPAR = 0;&amp;nbsp;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in DRUG_USE_CODES then NONALZH_DEMEN_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in PSYCH_CODES then NONALZH_DEMEN_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in OUD_CODES then NONALZH_DEMEN_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;end;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;*assigning -9 to missing DGNS values;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;do i = 1 to dim(DGNS);&lt;/DIV&gt;&lt;DIV&gt;if missing(NONALZH_DEMEN_MEDPAR) then do;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;if missing(DGNS[i]) then NONALZH_DEMEN_MEDPAR =-9;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;end;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* verifying*/&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Initialize non-alzheimer indicators to 0 */&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_1 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_2 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_3 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_4 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_5 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_6 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_7 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_8 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_9 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_10 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_11 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_12 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_13 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_14 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_15 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_16 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_17 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_18 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_19 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_20 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_21 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_22 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_23 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_24 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_25 = 0;&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_all = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Check DGNS_X_CD variables against nonalzhimers_codes */&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_1_CD) in nonalzhimers_codes then nonalzhimers_indicator_1 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_2_CD) in nonalzhimers_codes then nonalzhimers_indicator_2 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_3_CD) in nonalzhimers_codes then nonalzhimers_indicator_3 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_4_CD) in nonalzhimers_codes then nonalzhimers_indicator_4 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_5_CD) in nonalzhimers_codes then nonalzhimers_indicator_5 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_6_CD) in nonalzhimers_codes then nonalzhimers_indicator_6 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_7_CD) in nonalzhimers_codes then nonalzhimers_indicator_7 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_8_CD) in nonalzhimers_codes then nonalzhimers_indicator_8 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_9_CD) in nonalzhimers_codes then nonalzhimers_indicator_9 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_10_CD) in nonalzhimers_codes then nonalzhimers_indicator_10 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_11_CD) in nonalzhimers_codes then nonalzhimers_indicator_11 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_12_CD) in nonalzhimers_codes then nonalzhimers_indicator_12 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_13_CD) in nonalzhimers_codes then nonalzhimers_indicator_13 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_14_CD) in nonalzhimers_codes then nonalzhimers_indicator_14 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_15_CD) in nonalzhimers_codes then nonalzhimers_indicator_15 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_16_CD) in nonalzhimers_codes then nonalzhimers_indicator_16 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_17_CD) in nonalzhimers_codes then nonalzhimers_indicator_17 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_18_CD) in nonalzhimers_codes then nonalzhimers_indicator_18 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_19_CD) in nonalzhimers_codes then nonalzhimers_indicator_19 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_20_CD) in nonalzhimers_codes then nonalzhimers_indicator_20 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_21_CD) in nonalzhimers_codes then nonalzhimers_indicator_21 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_22_CD) in nonalzhimers_codes then nonalzhimers_indicator_22 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_23_CD) in nonalzhimers_codes then nonalzhimers_indicator_23 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_24_CD) in nonalzhimers_codes then nonalzhimers_indicator_24 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_25_CD) in nonalzhimers_codes then nonalzhimers_indicator_25 = 1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Sum the indicators and check for at least one match */&lt;/DIV&gt;&lt;DIV&gt;nonalzhimers_indicator_count = sum(of nonalzhimers_indicator_1-nonalzhimers_indicator_25);&lt;/DIV&gt;&lt;DIV&gt;if nonalzhimers_indicator_count &amp;gt; 0 then nonalzhimers_indicator_all = 1;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;****************************************************************************************************&lt;/DIV&gt;&lt;DIV&gt;/* Alzhimers diagnosis*&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/*Assign 1 to ALZH_MEDPAR for matches in alzhimers_codes;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;do i = 1 to dim(DGNS);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; if not missing(DGNS[i]) then do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in alzhimers_codes then ALZH_MEDPAR = 1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Assign 0 to ALZH_MEDPAR for other diagnosis codes */&lt;/DIV&gt;&lt;DIV&gt;do i = 1 to dim(DGNS);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; if missing(ALZH_MEDPAR) then do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in depression_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in nonalzhimers_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in pneumonia_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in hf_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in prknsn_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in stroke_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in stroke_exclusion_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in anxiety_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in bipolar_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in TBI_codes then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in DRUG_USE_CODES then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in PSYCH_CODES then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if strip(DGNS[i]) in OUD_CODES then ALZH_MEDPAR = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;end;&lt;/DIV&gt;&lt;DIV&gt;end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Assign -9 to ALZH_MEDPAR if all DGNS values are missing */&lt;/DIV&gt;&lt;DIV&gt;do i = 1 to dim(DGNS);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; if missing(ALZH_MEDPAR) then do;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if missing(DGNS[i]) then ALZH_MEDPAR = -9;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; end;&lt;/DIV&gt;&lt;DIV&gt;end;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* verifying*/&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Initialize alzheimer indicators to 0 */&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_1 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_2 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_3 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_4 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_5 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_6 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_7 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_8 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_9 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_10 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_11 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_12 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_13 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_14 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_15 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_16 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_17 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_18 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_19 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_20 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_21 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_22 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_23 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_24 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_25 = 0;&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_all = 0;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Check DGNS_X_CD variables against alzhimers_codes */&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_1_CD) in alzhimers_codes then alzh_indicator_1 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_2_CD) in alzhimers_codes then alzh_indicator_2 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_3_CD) in alzhimers_codes then alzh_indicator_3 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_4_CD) in alzhimers_codes then alzh_indicator_4 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_5_CD) in alzhimers_codes then alzh_indicator_5 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_6_CD) in alzhimers_codes then alzh_indicator_6 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_7_CD) in alzhimers_codes then alzh_indicator_7 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_8_CD) in alzhimers_codes then alzh_indicator_8 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_9_CD) in alzhimers_codes then alzh_indicator_9 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_10_CD) in alzhimers_codes then alzh_indicator_10 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_11_CD) in alzhimers_codes then alzh_indicator_11 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_12_CD) in alzhimers_codes then alzh_indicator_12 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_13_CD) in alzhimers_codes then alzh_indicator_13 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_14_CD) in alzhimers_codes then alzh_indicator_14 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_15_CD) in alzhimers_codes then alzh_indicator_15 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_16_CD) in alzhimers_codes then alzh_indicator_16 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_17_CD) in alzhimers_codes then alzh_indicator_17 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_18_CD) in alzhimers_codes then alzh_indicator_18 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_19_CD) in alzhimers_codes then alzh_indicator_19 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_20_CD) in alzhimers_codes then alzh_indicator_20 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_21_CD) in alzhimers_codes then alzh_indicator_21 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_22_CD) in alzhimers_codes then alzh_indicator_22 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_23_CD) in alzhimers_codes then alzh_indicator_23 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_24_CD) in alzhimers_codes then alzh_indicator_24 = 1;&lt;/DIV&gt;&lt;DIV&gt;if strip(DGNS_25_CD) in alzhimers_codes then alzh_indicator_25 = 1;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;/* Sum the indicators and check for at least one match */&lt;/DIV&gt;&lt;DIV&gt;alzh_indicator_count = sum(of alzh_indicator_1-alzh_indicator_25);&lt;/DIV&gt;&lt;DIV&gt;if alzh_indicator_count &amp;gt; 0 then alzh_indicator_all = 1;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 15:43:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-and-applying-a-loop-but-it-s-failing/m-p/955482#M373155</guid>
      <dc:creator>LuisMijares</dc:creator>
      <dc:date>2025-01-08T15:43:18Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a macro and applying a loop but it's failing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-and-applying-a-loop-but-it-s-failing/m-p/955571#M373183</link>
      <description>&lt;P&gt;Not sure if you're still looking for a solution, but if so, I would suggest putting this code in a code block (using the little SAS icon in the formatting tools when you're submitting a question here) or in an actual text editor that allows block indentation and then making all the indentation correct - in particular, the do-end blocks:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if x&amp;gt;3 then do;
    if y&amp;gt;7 then do;
        * stuff ;
    end;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This will really help reveal where you might be missing a DO -- the error message you're getting seems to indicate that you have a stray END somewhere.&amp;nbsp; I looked through your code (I'm very familiar with MedPAR) and I don't see one -- there's the one that looks out of place, but it appears to be commented out - right above the first /* verifying */ - so it shouldn't be causing a problem.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A few suggestions for making your code less repetitive / more efficient:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; -- inside the loop where you keep doing strip(dgns[i]) --- instead of this, first thing inside the loop, just do this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;dgns[i]=strip(dgns[i]);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;...after that, you don't need strip anymore.&lt;/P&gt;
&lt;P&gt;I'm not sure I understand the point of the indicator steps.&amp;nbsp; Are you just trying to preserve the location in the array where you found the code of interest?&amp;nbsp; If so, you can skip that entire thing and instead modify your main loop for a given condition like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
do i=1 to dim(DGNS);
  if missing(dgns[i]) then leave;
  dgns[i]=strip(dgns[i]);  * i do not think this is even needed ;
  if dgns[i] in depression_codes then do;
    DEPRESSION_MEDPAR=1;
    depression_pos=i;  * save the location in the array where this occurred ;
    leave;
  end;
end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the two LEAVE statements -- the first says, if we're reached the point in the array where we find a missing dgns, we can exit the loop - there is no need to check further.&amp;nbsp; MedPAR does not have blanks followed by more codes.&amp;nbsp; The second leave says, we've found the condition (depression) of interest -- set our flag DEPRESSION_MEDPAR to 1, store the position (i) as depression_pos, and leave (no need to keep checking unless for some reason you care if there is more than 1 depression code for the same visit - in general, this is not useful).&amp;nbsp; If you do for whatever reason want to count all the positions where depression is present, then do this instead:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;depression_count=0;
do i=1 to dim(DGNS);
  if missing(dgns[i]) then leave;
  dgns[i]=strip(dgns[i]);  * i do not think this is even needed ;
  if dgns[i] in depression_codes then do;
    DEPRESSION_MEDPAR=1;
    depression_count+1;  * keep track of the number of depression codes found ;
  end;
end;
depression_count_all=(depression_count&amp;gt;0);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note the 2nd leave statement is now gone, so the loop will continue until it finds the first missing dgns.&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2025 23:26:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-and-applying-a-loop-but-it-s-failing/m-p/955571#M373183</guid>
      <dc:creator>quickbluefish</dc:creator>
      <dc:date>2025-01-08T23:26:35Z</dc:date>
    </item>
    <item>
      <title>Re: Creating a macro and applying a loop but it's failing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-and-applying-a-loop-but-it-s-failing/m-p/955574#M373185</link>
      <description>&lt;P&gt;Didn't we already figure this out on your first posting?&lt;/P&gt;
&lt;P&gt;You have a statement comment in the code that was missing its semicolon. That turned one of the DO statements into part of the comment.&amp;nbsp; Hence you ended up with an extra END statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Troubleshooting-a-Macro-Error-Resolving-No-Matching-DO-SELECT/td-p/955486/jump-to/first-unread-message" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Troubleshooting-a-Macro-Error-Resolving-No-Matching-DO-SELECT/td-p/955486/jump-to/first-unread-message&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Jan 2025 00:57:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-a-macro-and-applying-a-loop-but-it-s-failing/m-p/955574#M373185</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-01-09T00:57:37Z</dc:date>
    </item>
  </channel>
</rss>

