<?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: macro loop for multiple variable combination outputs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-for-multiple-variable-combination-outputs/m-p/347381#M80227</link>
    <description>Thanks very much for your suggestion. I'll have a look. Best,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Karen&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 05 Apr 2017 14:31:57 GMT</pubDate>
    <dc:creator>ka2yee</dc:creator>
    <dc:date>2017-04-05T14:31:57Z</dc:date>
    <item>
      <title>macro loop for multiple variable combination outputs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-for-multiple-variable-combination-outputs/m-p/347191#M80156</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could use some advice on how to tackle obtaining weights for multiple variable combinations.&amp;nbsp; I was able to write the following code and have it work successfully:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*weight for sex=female, age_group=18-34; urban_zone=metro-calgary*/&lt;BR /&gt;proc sql;&lt;BR /&gt;&amp;nbsp;create table work.wt_by_sexAgeUz as&lt;BR /&gt;&amp;nbsp;select b.sex_num, b.age_group1, a.urban_zone, (b.tot_sexage_ahs_pop/&amp;amp;tot_ahs_pop)*a.uz_ahs_pop format=comma12.3 as weight&lt;BR /&gt;&amp;nbsp;&amp;nbsp;from (select urban_zone, ahs_pop as uz_ahs_pop&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; from work.registry_pop_sum_uz&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; where urban_zone='METRO-CALGARY'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp; ) as a&lt;BR /&gt;&amp;nbsp;, (select sex_num, age_group1, ahs_pop as tot_sexage_ahs_pop&lt;BR /&gt;&amp;nbsp;&amp;nbsp;from work.registry_pop_sum_SexAge&lt;BR /&gt;&amp;nbsp;&amp;nbsp;where sex_num=0 and age_group1='18-34'&lt;BR /&gt;&amp;nbsp;&amp;nbsp;) as b;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;but now what I'd like to do is to obtain results for various combinations.&amp;nbsp; For example:&lt;/P&gt;&lt;P&gt;1) keep&amp;nbsp;sex= female and urban_zone='METRO-CALGARY' but calculate weights for each of remaining age groups&lt;/P&gt;&lt;P&gt;2) keep sex=female and change urban_zone='METRO-EDMONTON' and calculate weights for each of the age groups&lt;/P&gt;&lt;P&gt;3) repeat 1 and 2 with sex=male&lt;/P&gt;&lt;P&gt;4) repeat 2 but change out the urban_zone with the other 6 categories I have&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I have is:&lt;/P&gt;&lt;P&gt;sex = male or female (2 categories total)&lt;/P&gt;&lt;P&gt;age_group = '18-34', '35-44', '45-54', etc. (8 categories total)&lt;/P&gt;&lt;P&gt;urban_zone = 'metro-calgary', 'metro-edmonton', etc. (20 categories total)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So there is a lot of combinations to obtain weights for.&amp;nbsp;&amp;nbsp; I thought about macros but don't know how to dyanmically change out the age category and urban_zone that is in quotations in the proc sql statements above.&amp;nbsp; Appreciate any thoughts.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry the attachement isn't working:&amp;nbsp; here is the structure of the dataset for registry_pop_sum_uz:&lt;/P&gt;&lt;P&gt;urban_zone, ahs_pop&lt;/P&gt;&lt;P&gt;metro-calgary, 978,418&lt;/P&gt;&lt;P&gt;metro-edmonton, 723,150&lt;/P&gt;&lt;P&gt;rural-calgary, 81,662,&lt;/P&gt;&lt;P&gt;etc.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 21:50:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-for-multiple-variable-combination-outputs/m-p/347191#M80156</guid>
      <dc:creator>ka2yee</dc:creator>
      <dc:date>2017-04-04T21:50:52Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop for multiple variable combination outputs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-for-multiple-variable-combination-outputs/m-p/347202#M80160</link>
      <description>&lt;P&gt;We can't replicate your data without numbers but my suggestion would be to step outside of SQL and look first at PROC MEANS/SUMMARY to generate all the different combinations you'll need. Look at the WAYS and TYPES statements in PROC MEANS that allows you to control the levels of aggregation. Or you can use the CLASSDATA option to specifically specify the levels of interest.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 22:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-for-multiple-variable-combination-outputs/m-p/347202#M80160</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-04-04T22:47:11Z</dc:date>
    </item>
    <item>
      <title>Re: macro loop for multiple variable combination outputs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-loop-for-multiple-variable-combination-outputs/m-p/347381#M80227</link>
      <description>Thanks very much for your suggestion. I'll have a look. Best,&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Karen&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 05 Apr 2017 14:31:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-loop-for-multiple-variable-combination-outputs/m-p/347381#M80227</guid>
      <dc:creator>ka2yee</dc:creator>
      <dc:date>2017-04-05T14:31:57Z</dc:date>
    </item>
  </channel>
</rss>

