<?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: How to simplify/shorten array programming in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841044#M332542</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This sort of problem where you use arrays to loop over codes and months can often be made much easier if you transpose your data into a vertical format, rather than wide.&amp;nbsp; In this case,&amp;nbsp; I would transpose the data to make each ID have 36 records (12 months * 3 codes per month).&amp;nbsp; You could do that like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tran (keep=dummyid month code EnrollmentType) ;
  set have ;
  array codes{3,12} 
    Enroll_TYPE_CD_01_01 - Enroll_TYPE_CD_01_12
    Enroll_TYPE_CD_02_01 - Enroll_TYPE_CD_02_12
    Enroll_TYPE_CD_03_01 - Enroll_TYPE_CD_03_12
  ;
  do month=1 to 12 ;
    do code=1 to 3 ;
      EnrollmentType=codes(code,month) ;
      output ;
    end ;
  end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have data in that format, it's straight forward to summarize by month, or code, or whatever you want.&amp;nbsp; I think what you want is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
  select dummyid, month, max((EnrollmentType=1)) as EnrollmentCat1
  from tran
  group by dummyid,month
 ;      
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that since your variable is named EnrollmentCat1, this suggests you have other enrollment categories of interest.&amp;nbsp; So in you may want to transpose your data to have one record per dummyid, enrollmentCat, month, code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Early in my career I was a fan of using arrays to loop over data like this.&amp;nbsp; Then I was lucky to have a boss who pointed out that often if you restructure your data, the code to analyze the data becomes much easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2022 23:40:13 GMT</pubDate>
    <dc:creator>Quentin</dc:creator>
    <dc:date>2022-10-26T23:40:13Z</dc:date>
    <item>
      <title>How to simplify/shorten array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/840981#M332503</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I have 36 (3 codes per month) enrollment type codes and wanted to generate flags per month to show if one person had a particular enrollment type. The array code I use as below is so long. Is there anyway to simplify/shorten it?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* Dummy data I have */&lt;BR /&gt;data have;&lt;BR /&gt;infile datalines truncover dsd;&lt;BR /&gt;input DummyID $ Enroll_TYPE_CD_01_01 Enroll_TYPE_CD_01_02 Enroll_TYPE_CD_01_03 Enroll_TYPE_CD_01_04 Enroll_TYPE_CD_01_05 Enroll_TYPE_CD_01_06&lt;BR /&gt;Enroll_TYPE_CD_01_07 Enroll_TYPE_CD_01_02 Enroll_TYPE_CD_01_09 Enroll_TYPE_CD_01_10 Enroll_TYPE_CD_01_11 Enroll_TYPE_CD_01_12&lt;BR /&gt;Enroll_TYPE_CD_02_01 Enroll_TYPE_CD_02_02 Enroll_TYPE_CD_02_03 Enroll_TYPE_CD_02_04 Enroll_TYPE_CD_02_05 Enroll_TYPE_CD_02_06&lt;BR /&gt;Enroll_TYPE_CD_02_07 Enroll_TYPE_CD_02_02 Enroll_TYPE_CD_02_09 Enroll_TYPE_CD_02_10 Enroll_TYPE_CD_02_11 Enroll_TYPE_CD_02_12&lt;BR /&gt;Enroll_TYPE_CD_03_01 Enroll_TYPE_CD_03_02 Enroll_TYPE_CD_03_03 Enroll_TYPE_CD_03_04 Enroll_TYPE_CD_03_05 Enroll_TYPE_CD_03_06&lt;BR /&gt;Enroll_TYPE_CD_03_07 Enroll_TYPE_CD_03_02 Enroll_TYPE_CD_03_09 Enroll_TYPE_CD_03_10 Enroll_TYPE_CD_03_11 Enroll_TYPE_CD_03_12&lt;BR /&gt;;&lt;BR /&gt;datalines;&lt;BR /&gt;Person01,1,1,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person02,1,1,1,1,1,1,2,1,1,1,1,1,,,,,,,3,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person03,2,2,2,2,2,2,2,2,2,2,2,2,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person04,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person05,1,1,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person06,1,1,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person07,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person08,1,1,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person09,1,1,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person10,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person11,2,2,2,2,2,2,2,2,2,2,2,2,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person12,,,,,,,2,2,2,2,2,2,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person13,1,1,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person14,1,1,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person15,2,2,2,2,2,2,2,2,2,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person16,1,1,1,1,1,1,2,2,2,1,1,1,,,,,,,1,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person17,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,,,,,,,,,,,,&lt;BR /&gt;Person18,2,2,2,2,1,1,1,1,1,1,1,1,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;Person19,3,3,,,,,3,,,,,,2,2,3,3,3,3,,,,,,,,,2,2,2,2,3,,,,,&lt;BR /&gt;Person20,4,4,4,4,4,4,4,4,4,4,4,,,,,,,,,,,,,,,,,,,,,,,,,&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;/* Code I use */&lt;BR /&gt;data have1;&lt;BR /&gt;set have;&lt;BR /&gt;array Enrl_tp_01 Enroll_TYPE_CD_01_01 Enroll_TYPE_CD_02_01 Enroll_TYPE_CD_03_01;&lt;BR /&gt;array Enrl_tp_02 Enroll_TYPE_CD_01_02 Enroll_TYPE_CD_02_02 Enroll_TYPE_CD_03_02;&lt;BR /&gt;array Enrl_tp_03 Enroll_TYPE_CD_01_03 Enroll_TYPE_CD_02_03 Enroll_TYPE_CD_03_03;&lt;BR /&gt;array Enrl_tp_04 Enroll_TYPE_CD_01_04 Enroll_TYPE_CD_02_04 Enroll_TYPE_CD_03_04;&lt;BR /&gt;array Enrl_tp_05 Enroll_TYPE_CD_01_05 Enroll_TYPE_CD_02_05 Enroll_TYPE_CD_03_05;&lt;BR /&gt;array Enrl_tp_06 Enroll_TYPE_CD_01_06 Enroll_TYPE_CD_02_06 Enroll_TYPE_CD_03_06;&lt;BR /&gt;array Enrl_tp_07 Enroll_TYPE_CD_01_07 Enroll_TYPE_CD_02_07 Enroll_TYPE_CD_03_07;&lt;BR /&gt;array Enrl_tp_08 Enroll_TYPE_CD_01_08 Enroll_TYPE_CD_02_08 Enroll_TYPE_CD_03_08;&lt;BR /&gt;array Enrl_tp_09 Enroll_TYPE_CD_01_09 Enroll_TYPE_CD_02_09 Enroll_TYPE_CD_03_09;&lt;BR /&gt;array Enrl_tp_10 Enroll_TYPE_CD_01_10 Enroll_TYPE_CD_02_10 Enroll_TYPE_CD_03_10;&lt;BR /&gt;array Enrl_tp_11 Enroll_TYPE_CD_01_11 Enroll_TYPE_CD_02_11 Enroll_TYPE_CD_03_11;&lt;BR /&gt;array Enrl_tp_12 Enroll_TYPE_CD_01_12 Enroll_TYPE_CD_02_12 Enroll_TYPE_CD_03_12;&lt;/P&gt;&lt;P&gt;array Grp_flg_01 flag_Enrlcat1_01_01 flag_Enrlcat1_02_01 flag_Enrlcat1_03_01;&lt;BR /&gt;array Grp_flg_02 flag_Enrlcat1_01_02 flag_Enrlcat1_02_02 flag_Enrlcat1_03_02;&lt;BR /&gt;array Grp_flg_03 flag_Enrlcat1_01_03 flag_Enrlcat1_02_03 flag_Enrlcat1_03_03;&lt;BR /&gt;array Grp_flg_04 flag_Enrlcat1_01_04 flag_Enrlcat1_02_04 flag_Enrlcat1_03_04;&lt;BR /&gt;array Grp_flg_05 flag_Enrlcat1_01_05 flag_Enrlcat1_02_05 flag_Enrlcat1_03_05;&lt;BR /&gt;array Grp_flg_06 flag_Enrlcat1_01_06 flag_Enrlcat1_02_06 flag_Enrlcat1_03_06;&lt;BR /&gt;array Grp_flg_07 flag_Enrlcat1_01_07 flag_Enrlcat1_02_07 flag_Enrlcat1_03_07;&lt;BR /&gt;array Grp_flg_08 flag_Enrlcat1_01_08 flag_Enrlcat1_02_08 flag_Enrlcat1_03_08;&lt;BR /&gt;array Grp_flg_09 flag_Enrlcat1_01_09 flag_Enrlcat1_02_09 flag_Enrlcat1_03_09;&lt;BR /&gt;array Grp_flg_10 flag_Enrlcat1_01_10 flag_Enrlcat1_02_10 flag_Enrlcat1_03_10;&lt;BR /&gt;array Grp_flg_11 flag_Enrlcat1_01_11 flag_Enrlcat1_02_11 flag_Enrlcat1_03_11;&lt;BR /&gt;array Grp_flg_12 flag_Enrlcat1_01_12 flag_Enrlcat1_02_12 flag_Enrlcat1_03_12;&lt;/P&gt;&lt;P&gt;do over Enrl_tp_01;&lt;BR /&gt;if Enrl_tp_01=1 then Grp_flg_01=1;&lt;BR /&gt;else Grp_flg_01=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201801=max(flag_Enrlcat1_01_01, flag_Enrlcat1_02_01, flag_Enrlcat1_03_01);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_02;&lt;BR /&gt;if Enrl_tp_02=1 then Grp_flg_02=1;&lt;BR /&gt;else Grp_flg_02=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201802=max(flag_Enrlcat1_01_02, flag_Enrlcat1_02_02, flag_Enrlcat1_03_02);&lt;BR /&gt;do over Enrl_tp_03;&lt;BR /&gt;if Enrl_tp_03=1 then Grp_flg_03=1;&lt;BR /&gt;else Grp_flg_03=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201803=max(flag_Enrlcat1_01_03, flag_Enrlcat1_02_03, flag_Enrlcat1_03_03);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_04;&lt;BR /&gt;if Enrl_tp_04=1 then Grp_flg_04=1;&lt;BR /&gt;else Grp_flg_04=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201804=max(flag_Enrlcat1_01_04, flag_Enrlcat1_02_04, flag_Enrlcat1_03_04);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_05;&lt;BR /&gt;if Enrl_tp_05=1 then Grp_flg_05=1;&lt;BR /&gt;else Grp_flg_05=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201805=max(flag_Enrlcat1_01_05, flag_Enrlcat1_02_05, flag_Enrlcat1_03_05);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_06;&lt;BR /&gt;if Enrl_tp_06=1 then Grp_flg_06=1;&lt;BR /&gt;else Grp_flg_06=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201806=max(flag_Enrlcat1_01_06, flag_Enrlcat1_02_06, flag_Enrlcat1_03_06);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_07;&lt;BR /&gt;if Enrl_tp_07=1 then Grp_flg_07=1;&lt;BR /&gt;else Grp_flg_07=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201807=max(flag_Enrlcat1_01_07, flag_Enrlcat1_02_07, flag_Enrlcat1_03_07);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_08;&lt;BR /&gt;if Enrl_tp_08=1 then Grp_flg_08=1;&lt;BR /&gt;else Grp_flg_08=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201808=max(flag_Enrlcat1_01_08, flag_Enrlcat1_02_08, flag_Enrlcat1_03_08);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_09;&lt;BR /&gt;if Enrl_tp_09=1 then Grp_flg_09=1;&lt;BR /&gt;else Grp_flg_09=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201809=max(flag_Enrlcat1_01_09, flag_Enrlcat1_02_09, flag_Enrlcat1_03_09);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_10;&lt;BR /&gt;if Enrl_tp_10=1 then Grp_flg_10=1;&lt;BR /&gt;else Grp_flg_10=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201810=max(flag_Enrlcat1_01_10, flag_Enrlcat1_02_10, flag_Enrlcat1_03_10);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_11;&lt;BR /&gt;if Enrl_tp_11=1 then Grp_flg_11=1;&lt;BR /&gt;else Grp_flg_11=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201811=max(flag_Enrlcat1_01_11, flag_Enrlcat1_02_11, flag_Enrlcat1_03_11);&lt;/P&gt;&lt;P&gt;do over Enrl_tp_12;&lt;BR /&gt;if Enrl_tp_12=1 then Grp_flg_12=1;&lt;BR /&gt;else Grp_flg_12=0;&lt;BR /&gt;end;&lt;BR /&gt;flag_Enrlcat1_201812=max(flag_Enrlcat1_01_12, flag_Enrlcat1_02_12, flag_Enrlcat1_03_12);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;/* Dummy data I want to generate */&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select distinct DummyID&lt;BR /&gt;,flag_Enrlcat1_201801&lt;BR /&gt;,flag_Enrlcat1_201802&lt;BR /&gt;,flag_Enrlcat1_201803&lt;BR /&gt;,flag_Enrlcat1_201804&lt;BR /&gt;,flag_Enrlcat1_201805&lt;BR /&gt;,flag_Enrlcat1_201806&lt;BR /&gt;,flag_Enrlcat1_201807&lt;BR /&gt;,flag_Enrlcat1_201808&lt;BR /&gt;,flag_Enrlcat1_201809&lt;BR /&gt;,flag_Enrlcat1_201810&lt;BR /&gt;,flag_Enrlcat1_201811&lt;BR /&gt;,flag_Enrlcat1_201812&lt;BR /&gt;from have1&lt;BR /&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 17:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/840981#M332503</guid>
      <dc:creator>lichee</dc:creator>
      <dc:date>2022-10-26T17:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify/shorten array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/840987#M332507</link>
      <description>&lt;P&gt;1st thing. I think you have a typo in your have data set. The variable&amp;nbsp;&lt;SPAN&gt;Enroll_TYPE_CD_01_02 appears twice. One of them should be&amp;nbsp;Enroll_TYPE_CD_01_08 right?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;I simplified the code that creates the have data set a bit. Is the below data correct?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines truncover dsd;
input DummyID $ Enroll_TYPE_CD_01_01 - Enroll_TYPE_CD_01_12
                Enroll_TYPE_CD_02_01 - Enroll_TYPE_CD_02_12
                Enroll_TYPE_CD_03_01 - Enroll_TYPE_CD_03_12
;
datalines;
Person01,1,1,1,1,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , 
Person02,1,1,1,1,1,1,2,1,1,1,1,1, , , , , , ,3, , , , , , , , , , , , , , , , , 
Person03,2,2,2,2,2,2,2,2,2,2,2,2, , , , , , , , , , , , , , , , , , , , , , , , 
Person04,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , , , , , 
Person05,1,1,1,1,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , 
Person06,1,1,1,1,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , 
Person07,1,1,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , , , 
Person08,1,1,1,1,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , 
Person09,1,1,1,1,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , 
Person10,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1, , , , , , , , , , , , , , , , , , , , , 
Person11,2,2,2,2,2,2,2,2,2,2,2,2, , , , , , , , , , , , , , , , , , , , , , , , 
Person12, , , , , , ,2,2,2,2,2,2, , , , , , , , , , , , , , , , , , , , , , , , 
Person13,1,1,1,1,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , 
Person14,1,1,1,1,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , 
Person15,2,2,2,2,2,2,2,2,2,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , 
Person16,1,1,1,1,1,1,2,2,2,1,1,1, , , , , , ,1, , , , , , , , , , , , , , , , , 
Person17,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, , , , , , , , , , , , 
Person18,2,2,2,2,1,1,1,1,1,1,1,1, , , , , , , , , , , , , , , , , , , , , , , , 
Person19,3,3, , , , ,3, , , , , ,2,2,3,3,3,3, , , , , , , , ,2,2,2,2,3, , , , , 
Person20,4,4,4,4,4,4,4,4,4,4,4, , , , , , , , , , , , , , , , , , , , , , , , , 
;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2022 18:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/840987#M332507</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-26T18:12:22Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify/shorten array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/840992#M332508</link>
      <description>Yes, you are correct! It should be Enroll_TYPE_CD_01_08, instead of Enroll_TYPE_CD_01_02, Thanks a lot!</description>
      <pubDate>Wed, 26 Oct 2022 18:19:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/840992#M332508</guid>
      <dc:creator>lichee</dc:creator>
      <dc:date>2022-10-26T18:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify/shorten array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/840996#M332510</link>
      <description>&lt;P&gt;Ok. This gives you the same result as your posted code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want(drop = enroll: v);
   set have;
   array enroll  Enroll_TYPE_CD_01_01 -- Enroll_TYPE_CD_03_12;
   array flag{*} flag_Enrlcat1_201801 - flag_Enrlcat1_201812 (12 * 0);

   call stdize('replace', 'mult=', 0, of flag[*], _N_);

   do over enroll;
      v = input(substr(vname(enroll), length(vname(enroll)) - 1), 8.);
      if enroll = 1 then flag[v] = 1;
   end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Result:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;DummyID   flag_Enrlcat1_201801 ... flag_Enrlcat1_201812
Person01  1  1  1  1  1  1  1  1  1  1  1  1
Person02  1  1  1  1  1  1  0  1  1  1  1  1
Person03  0  0  0  0  0  0  0  0  0  0  0  0
Person04  1  1  1  1  1  1  1  1  0  0  0  0
Person05  1  1  1  1  1  1  1  1  1  1  1  1
Person06  1  1  1  1  1  1  1  1  1  1  1  1
Person07  1  1  1  1  1  1  1  1  1  1  0  0
Person08  1  1  1  1  1  1  1  1  1  1  1  1
Person09  1  1  1  1  1  1  1  1  1  1  1  1
Person10  1  1  1  0  0  0  0  0  0  0  0  0
Person11  0  0  0  0  0  0  0  0  0  0  0  0
Person12  0  0  0  0  0  0  0  0  0  0  0  0
Person13  1  1  1  1  1  1  1  1  1  1  1  1
Person14  1  1  1  1  1  1  1  1  1  1  1  1
Person15  0  0  0  0  0  0  0  0  0  1  1  1
Person16  1  1  1  1  1  1  1  0  0  1  1  1
Person17  1  1  1  1  1  1  1  1  1  1  1  1
Person18  0  0  0  0  1  1  1  1  1  1  1  1
Person19  0  0  0  0  0  0  0  0  0  0  0  0
Person20  0  0  0  0  0  0  0  0  0  0  0  0&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2022 18:36:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/840996#M332510</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-26T18:36:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify/shorten array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841009#M332515</link>
      <description>&lt;P&gt;Just use periods to mark the missing values and the data step to create the example data is much easier to write (and read).&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input DummyID $
    Enroll_TYPE_CD_01_01 - Enroll_TYPE_CD_01_12
    Enroll_TYPE_CD_02_01 - Enroll_TYPE_CD_02_12
    Enroll_TYPE_CD_03_01 - Enroll_TYPE_CD_03_12
  ;
datalines;
Person01 1 1 1 1 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
Person02 1 1 1 1 1 1 2 1 1 1 1 1 . . . . . . 3 . . . . . . . . . . . . . . . . .
Person03 2 2 2 2 2 2 2 2 2 2 2 2 . . . . . . . . . . . . . . . . . . . . . . . .
Person04 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Person05 1 1 1 1 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
Person06 1 1 1 1 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
Person07 1 1 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . . . .
Person08 1 1 1 1 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
Person09 1 1 1 1 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
Person10 2 2 2 2 2 2 2 2 2 2 2 2 1 1 1 . . . . . . . . . . . . . . . . . . . . .
Person11 2 2 2 2 2 2 2 2 2 2 2 2 . . . . . . . . . . . . . . . . . . . . . . . .
Person12 . . . . . . 2 2 2 2 2 2 . . . . . . . . . . . . . . . . . . . . . . . .
Person13 1 1 1 1 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
Person14 1 1 1 1 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
Person15 2 2 2 2 2 2 2 2 2 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
Person16 1 1 1 1 1 1 2 2 2 1 1 1 . . . . . . 1 . . . . . . . . . . . . . . . . .
Person17 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 . . . . . . . . . . . .
Person18 2 2 2 2 1 1 1 1 1 1 1 1 . . . . . . . . . . . . . . . . . . . . . . . .
Person19 3 3 . . . . 3 . . . . . 2 2 3 3 3 3 . . . . . . . . 2 2 2 2 3 . . . . .
Person20 4 4 4 4 4 4 4 4 4 4 4 . . . . . . . . . . . . . . . . . . . . . . . . .
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI-SPOILER&gt;
&lt;P&gt;Since you seem to only want those FLAG_.... variables this should do it much easier (and clearer).&amp;nbsp; You just need two arrays. One for the input variables and one for the output variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have;
  array enroll [3,12] 
    Enroll_TYPE_CD_01_01 - Enroll_TYPE_CD_01_12
    Enroll_TYPE_CD_02_01 - Enroll_TYPE_CD_02_12
    Enroll_TYPE_CD_03_01 - Enroll_TYPE_CD_03_12
  ;
  array flag [12] flag_Enrlcat1_201801 - flag_Enrlcat1_201812 ;
  do month=1 to 12;
    do type=1 to 3 ;
      flag[month]=max(0,flag[month],enroll[type,month]=1 );
    end;
  end;
  keep dummyid flag_: ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;                  f    f    f    f    f    f    f    f    f    f    f    f
                  l    l    l    l    l    l    l    l    l    l    l    l
                  a    a    a    a    a    a    a    a    a    a    a    a
                  g    g    g    g    g    g    g    g    g    g    g    g
                  _    _    _    _    _    _    _    _    _    _    _    _
                  E    E    E    E    E    E    E    E    E    E    E    E
                  n    n    n    n    n    n    n    n    n    n    n    n
                  r    r    r    r    r    r    r    r    r    r    r    r
                  l    l    l    l    l    l    l    l    l    l    l    l
                  c    c    c    c    c    c    c    c    c    c    c    c
                  a    a    a    a    a    a    a    a    a    a    a    a
                  t    t    t    t    t    t    t    t    t    t    t    t
                  1    1    1    1    1    1    1    1    1    1    1    1
         D        _    _    _    _    _    _    _    _    _    _    _    _
         u        2    2    2    2    2    2    2    2    2    2    2    2
         m        0    0    0    0    0    0    0    0    0    0    0    0
         m        1    1    1    1    1    1    1    1    1    1    1    1
 O       y        8    8    8    8    8    8    8    8    8    8    8    8
 b       I        0    0    0    0    0    0    0    0    0    1    1    1
 s       D        1    2    3    4    5    6    7    8    9    0    1    2

 1    Person01    1    1    1    1    1    1    1    1    1    1    1    1
 2    Person02    1    1    1    1    1    1    0    1    1    1    1    1
 3    Person03    0    0    0    0    0    0    0    0    0    0    0    0
 4    Person04    1    1    1    1    1    1    1    1    0    0    0    0
 5    Person05    1    1    1    1    1    1    1    1    1    1    1    1
 6    Person06    1    1    1    1    1    1    1    1    1    1    1    1
 7    Person07    1    1    1    1    1    1    1    1    1    1    0    0
 8    Person08    1    1    1    1    1    1    1    1    1    1    1    1
 9    Person09    1    1    1    1    1    1    1    1    1    1    1    1
10    Person10    1    1    1    0    0    0    0    0    0    0    0    0
11    Person11    0    0    0    0    0    0    0    0    0    0    0    0
12    Person12    0    0    0    0    0    0    0    0    0    0    0    0
13    Person13    1    1    1    1    1    1    1    1    1    1    1    1
14    Person14    1    1    1    1    1    1    1    1    1    1    1    1
15    Person15    0    0    0    0    0    0    0    0    0    1    1    1
16    Person16    1    1    1    1    1    1    1    0    0    1    1    1
17    Person17    1    1    1    1    1    1    1    1    1    1    1    1
18    Person18    0    0    0    0    1    1    1    1    1    1    1    1
19    Person19    0    0    0    0    0    0    0    0    0    0    0    0
20    Person20    0    0    0    0    0    0    0    0    0    0    0    0
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 19:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841009#M332515</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-26T19:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify/shorten array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841010#M332516</link>
      <description>&lt;P&gt;If you are going to use DO OVER why go the whole way and use implicit indexing for both arrays?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data do_over;
   set have;
   array enroll  Enroll_TYPE_CD_01_01 -- Enroll_TYPE_CD_03_12;
   array flag (month) flag_Enrlcat1_201801 - flag_Enrlcat1_201812 (12 * 0);

   call stdize('replace', 'mult=', 0, of flag_: , _N_);

   do over enroll;
      month = input(substr(vname(enroll), length(vname(enroll)) - 1), 8.);
      if enroll = 1 then flag = 1;
   end;

   drop enroll: month;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 19:55:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841010#M332516</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-10-26T19:55:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify/shorten array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841030#M332534</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;Good question. Just a preference thing I guess. I like the implicit array in many situations. However I don't like when I'm forced to specify the index variable instead of _I_ explicitly. To me, It's not as slick anymore. Also, in this situation, I think it makes it more clear that flag is not a variable, but an array.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Speaking of slick, the 2d array is probably the way to go here. Crossed my mind, but I couldn't quite get there &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt; One of the few good real-life uses of the 2d array.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 20:52:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841030#M332534</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2022-10-26T20:52:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify/shorten array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841044#M332542</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This sort of problem where you use arrays to loop over codes and months can often be made much easier if you transpose your data into a vertical format, rather than wide.&amp;nbsp; In this case,&amp;nbsp; I would transpose the data to make each ID have 36 records (12 months * 3 codes per month).&amp;nbsp; You could do that like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tran (keep=dummyid month code EnrollmentType) ;
  set have ;
  array codes{3,12} 
    Enroll_TYPE_CD_01_01 - Enroll_TYPE_CD_01_12
    Enroll_TYPE_CD_02_01 - Enroll_TYPE_CD_02_12
    Enroll_TYPE_CD_03_01 - Enroll_TYPE_CD_03_12
  ;
  do month=1 to 12 ;
    do code=1 to 3 ;
      EnrollmentType=codes(code,month) ;
      output ;
    end ;
  end ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once you have data in that format, it's straight forward to summarize by month, or code, or whatever you want.&amp;nbsp; I think what you want is:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql ;
  select dummyid, month, max((EnrollmentType=1)) as EnrollmentCat1
  from tran
  group by dummyid,month
 ;      
quit ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that since your variable is named EnrollmentCat1, this suggests you have other enrollment categories of interest.&amp;nbsp; So in you may want to transpose your data to have one record per dummyid, enrollmentCat, month, code.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Early in my career I was a fan of using arrays to loop over data like this.&amp;nbsp; Then I was lucky to have a boss who pointed out that often if you restructure your data, the code to analyze the data becomes much easier.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 23:40:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841044#M332542</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2022-10-26T23:40:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to simplify/shorten array programming</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841098#M332563</link>
      <description>I tried out all three ways, and they all worked very well. Tom's code seems most straightforward to me, so I'm go with his. Thank you all for all the guidance!</description>
      <pubDate>Thu, 27 Oct 2022 10:29:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-simplify-shorten-array-programming/m-p/841098#M332563</guid>
      <dc:creator>lichee</dc:creator>
      <dc:date>2022-10-27T10:29:51Z</dc:date>
    </item>
  </channel>
</rss>

