<?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 or Array in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Macro-or-Array/m-p/23571#M5222</link>
    <description>Why do you want/need to create a data set per area code at first place? &lt;BR /&gt;
This doesn't sound like a good idea.&lt;BR /&gt;
&lt;BR /&gt;
Anyway, here a possible solution:&lt;BR /&gt;
&lt;BR /&gt;
Data have;&lt;BR /&gt;
infile datalines truncover dlm=' ';&lt;BR /&gt;
input Area_Code Pop Emp;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 50 10&lt;BR /&gt;
2 100 20&lt;BR /&gt;
3 150 30&lt;BR /&gt;
4 200 40&lt;BR /&gt;
5 250 50&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select distinct cats('area_code_',area_code), cat('when(',Area_Code,') output ',cats('area_code_',area_code),';')&lt;BR /&gt;
    into :dslist separated by ' ', :WhenList separated by ' '&lt;BR /&gt;
    from have&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data &amp;amp;dslist;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  percent=emp/pop;&lt;BR /&gt;
  select(area_code);&lt;BR /&gt;
    &amp;amp;WhenList&lt;BR /&gt;
    otherwise;&lt;BR /&gt;
  end;&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Patrick</description>
    <pubDate>Tue, 18 May 2010 05:50:33 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2010-05-18T05:50:33Z</dc:date>
    <item>
      <title>Macro or Array</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-or-Array/m-p/23570#M5221</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
Here are my 2 sample datasets:&lt;BR /&gt;
Dataset1&lt;BR /&gt;
Area_Code&lt;BR /&gt;
1&lt;BR /&gt;
2&lt;BR /&gt;
3&lt;BR /&gt;
&lt;BR /&gt;
Dataset2&lt;BR /&gt;
Area_Code     Pop     Emp&lt;BR /&gt;
1                     50        10&lt;BR /&gt;
2                    100        20&lt;BR /&gt;
3                     150       30&lt;BR /&gt;
4                     200       40&lt;BR /&gt;
5                     250       50&lt;BR /&gt;
&lt;BR /&gt;
data area_code1 ;&lt;BR /&gt;
  set dataset2;&lt;BR /&gt;
  if area_code in (1);&lt;BR /&gt;
  percent=emp/pop;&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
I want to know if there is a way to have 3 separate datasets by area_code (ex. Area_code1, area_code2, and area_code3).  My above example only shows 3 area codes in dataset1.  What if I have 100 area codes in dataset1?  How do I replace the area_code in the program above without running it 100 times to perform the operation for each area code in dataset1 (1,2,3,4,etc)?&lt;BR /&gt;
&lt;BR /&gt;
Thanks in advance for your help.</description>
      <pubDate>Tue, 18 May 2010 05:09:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-or-Array/m-p/23570#M5221</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-05-18T05:09:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro or Array</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Macro-or-Array/m-p/23571#M5222</link>
      <description>Why do you want/need to create a data set per area code at first place? &lt;BR /&gt;
This doesn't sound like a good idea.&lt;BR /&gt;
&lt;BR /&gt;
Anyway, here a possible solution:&lt;BR /&gt;
&lt;BR /&gt;
Data have;&lt;BR /&gt;
infile datalines truncover dlm=' ';&lt;BR /&gt;
input Area_Code Pop Emp;&lt;BR /&gt;
datalines;&lt;BR /&gt;
1 50 10&lt;BR /&gt;
2 100 20&lt;BR /&gt;
3 150 30&lt;BR /&gt;
4 200 40&lt;BR /&gt;
5 250 50&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc sql noprint;&lt;BR /&gt;
  select distinct cats('area_code_',area_code), cat('when(',Area_Code,') output ',cats('area_code_',area_code),';')&lt;BR /&gt;
    into :dslist separated by ' ', :WhenList separated by ' '&lt;BR /&gt;
    from have&lt;BR /&gt;
  ;&lt;BR /&gt;
quit;&lt;BR /&gt;
&lt;BR /&gt;
data &amp;amp;dslist;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  percent=emp/pop;&lt;BR /&gt;
  select(area_code);&lt;BR /&gt;
    &amp;amp;WhenList&lt;BR /&gt;
    otherwise;&lt;BR /&gt;
  end;&lt;BR /&gt;
run ;&lt;BR /&gt;
&lt;BR /&gt;
Message was edited by: Patrick</description>
      <pubDate>Tue, 18 May 2010 05:50:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Macro-or-Array/m-p/23571#M5222</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-05-18T05:50:33Z</dc:date>
    </item>
  </channel>
</rss>

