<?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 macro/array/loop to fill large table shells by row? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846860#M334795</link>
    <description>That explains why I couldn't figure out the loop! Thanks so much</description>
    <pubDate>Tue, 29 Nov 2022 17:07:15 GMT</pubDate>
    <dc:creator>irvinery</dc:creator>
    <dc:date>2022-11-29T17:07:15Z</dc:date>
    <item>
      <title>Creating macro/array/loop to fill large table shells by row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846851#M334788</link>
      <description>&lt;P&gt;Hi fellow SAS programmers,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have to fill several large table shells by rows, and I can't figure out how to somewhat automate the process. Some of them are 40-50 rows long, so typing every line by hand is possible but not practical. The underlying data isn't really relevant, but coding example for a smaller table + desired output is below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;(1) The table shell (imported from an xlsx file):&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="irvinery_0-1669737936381.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77815iA8B72CD816378A3E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="irvinery_0-1669737936381.png" alt="irvinery_0-1669737936381.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;(2) Code for counts/numeric values:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+
	Total population for denominator in later tables
*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+;
proc sql;
select count(distinct person_id) into :row15 from tables.study_population;
quit;

*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+
	For patients with multiple index scripts, remove duplicated person_id to retain only 1
	per patient. since all on same day, does not matter which
*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+;
proc sort data=tables.study_population out=table1_unique nodupkey; by person_id; run; 

*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+
	Age
*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+;
title "Age (years) summary";
proc sql;
select count(distinct person_id) into :row2 from table1_unique;
select round(mean(index_age),0.01) into :row3 from table1_unique;
select round(std(index_age),0.01) into :row4 from table1_unique;
select round(median(index_age),0.01) into :row5 from table1_unique;
quit;

*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+
	Age Group
*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+;
title "Age Group Summary";
proc sql;
select count(distinct person_id) into :row7 from table1_unique where age_group = 1;
select count(distinct person_id) into :row8 from table1_unique where age_group = 2;
select count(distinct person_id) into :row9 from table1_unique where age_group = 3;
select count(distinct person_id) into :row10 from table1_unique where age_group = 4;
quit;

*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+
	Follow-up period duration
*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+;
proc sql;
select round(mean(followup),0.01) into :row12 from table1_unique;
select round(std(followup),0.01) into :row13 from table1_unique;
select round(median(followup),0.01) into :row14 from table1_unique;
quit;

*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+
	Output Results
*=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+=====+;
data table1;
format count $32.;
set table1_shell;
if row=2 then count=compress(put(&amp;amp;row2,comma10.0));
if row=3 then count=compress(put(&amp;amp;row3,best.));
if row=4 then count=compress(put(&amp;amp;row4,best.));
if row=5 then count=compress(put(&amp;amp;row5,best.));

if row=7 then count=compress(put(&amp;amp;row7,comma10.0));
if row=8 then count=compress(put(&amp;amp;row8,comma10.0));
if row=9 then count=compress(put(&amp;amp;row9,comma10.0));
if row=10 then count=compress(put(&amp;amp;row10,comma10.0));

if row=12 then count=compress(put(&amp;amp;row12,comma10.0));
if row=13 then count=compress(put(&amp;amp;row13,best.));
if row=14 then count=compress(put(&amp;amp;row14,best.));
if row=15 then count=compress(put(&amp;amp;row15,comma10.0));
run;&lt;BR /&gt;&lt;BR /&gt;proc report data=table1;&lt;BR /&gt;column metric count;&lt;BR /&gt;define metric / "Metric" display style=[asis=on];&lt;BR /&gt;define count / "Value";&lt;BR /&gt;run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;(3) The output table from this code:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="irvinery_1-1669738152703.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/77816i5F4BEA2019F36C35/image-size/medium?v=v2&amp;amp;px=400" role="button" title="irvinery_1-1669738152703.png" alt="irvinery_1-1669738152703.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My question is: How can I convert the final data step into a macro, array, etc. to reduce the amount of code I actually have to write. For example, I have another table shell with 60 rows, but the same format, i.e. "if row = X then count = &amp;amp;rowX", where x = 1 to x = 60.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've tried an array + do loop, and I can't figure out what's going wrong. I'm not super adept at imagining the macro compiling, and I think that's where the issue is. I appreciate any guidance my fellow programmers are able to offer!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 16:14:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846851#M334788</guid>
      <dc:creator>irvinery</dc:creator>
      <dc:date>2022-11-29T16:14:45Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro/array/loop to fill large table shells by row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846853#M334789</link>
      <description>&lt;P&gt;Seems like an extremely complex design, but I think what you are looking for is the SYMGET() function. Or perhaps even the SYMGETN() function.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count=compress(put(symgetn(cats('row',row)),comma10.0));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 29 Nov 2022 16:25:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846853#M334789</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-29T16:25:50Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro/array/loop to fill large table shells by row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846856#M334792</link>
      <description>&lt;P&gt;I have tried something similar, but still wasn't able to figure out how to loop it to do it for all rows that needed to be filled&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 16:45:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846856#M334792</guid>
      <dc:creator>irvinery</dc:creator>
      <dc:date>2022-11-29T16:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro/array/loop to fill large table shells by row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846859#M334794</link>
      <description>&lt;P&gt;There is no looping involved if you have a dataset with the variable ROW and the corresponding ROWn macro variables.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  set have ;
  countn=symgetn(cats('row',row));
  countc=put(countn,comma10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Nov 2022 17:04:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846859#M334794</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-11-29T17:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Creating macro/array/loop to fill large table shells by row?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846860#M334795</link>
      <description>That explains why I couldn't figure out the loop! Thanks so much</description>
      <pubDate>Tue, 29 Nov 2022 17:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Creating-macro-array-loop-to-fill-large-table-shells-by-row/m-p/846860#M334795</guid>
      <dc:creator>irvinery</dc:creator>
      <dc:date>2022-11-29T17:07:15Z</dc:date>
    </item>
  </channel>
</rss>

