<?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: Set up macro to create new datasets while adding a new variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Set-up-macro-to-create-new-datasets-while-adding-a-new-variable/m-p/875328#M345859</link>
    <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;this works perfectly!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 11 May 2023 18:49:41 GMT</pubDate>
    <dc:creator>kevsma</dc:creator>
    <dc:date>2023-05-11T18:49:41Z</dc:date>
    <item>
      <title>Set up macro to create new datasets while adding a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-up-macro-to-create-new-datasets-while-adding-a-new-variable/m-p/875309#M345853</link>
      <description>&lt;P&gt;Hello folks, I believe this is an easy one but somehow i can't figure out the macro to do it. I want to create 4 new datasets by specifying the value of a variable in an existing dataset. Below is my code which is very lengthy and redundant.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rcst1; set lcmf.cm20&amp;amp;fy1two.01a (keep=UCI RCAbrv Status); fy="&amp;amp;fy1two."; 
	where status in ('1','2'); run;

data rcst2; set lcmf.cm20&amp;amp;fy2two.01a (keep=UCI RCAbrv Status); fy="&amp;amp;fy2two."; 
	where status in ('1','2'); run;

data rcst3; set lcmf.cm20&amp;amp;fy3two.01a (keep=UCI RCAbrv Status); fy="&amp;amp;fy3two."; 
	where status in ('1','2'); run;

data rcst4; set lcmf.cm20&amp;amp;fy4two.01a (keep=UCI RCAbrv Status); fy="&amp;amp;fy4two."; 
	where status in ('1','2'); run;
&lt;BR /&gt;*combine/append all 4 new dataset into one;
data rcstall;
	set rcst1 rcst2 rcst3 rcst4; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Two things I wonder whether i can achieve:&lt;/P&gt;
&lt;P&gt;1. since the existing macro starts from 1 to 4, can i create another loop to go from 1 to 4 instead of copying and pasting so many lines?&lt;/P&gt;
&lt;P&gt;2. can I do one set command to append all four new datasets while adding a new variable "fy" to indicate the source of each dataset?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appreciate any feedback you may have. Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 17:53:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-up-macro-to-create-new-datasets-while-adding-a-new-variable/m-p/875309#M345853</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2023-05-11T17:53:45Z</dc:date>
    </item>
    <item>
      <title>Re: Set up macro to create new datasets while adding a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-up-macro-to-create-new-datasets-while-adding-a-new-variable/m-p/875314#M345854</link>
      <description>This could possibly be simplified further, what does fy1two to fy4two look like. &lt;BR /&gt;The INDSNAME option allows you to identify the input data set names.</description>
      <pubDate>Thu, 11 May 2023 18:03:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-up-macro-to-create-new-datasets-while-adding-a-new-variable/m-p/875314#M345854</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-11T18:03:19Z</dc:date>
    </item>
    <item>
      <title>Re: Set up macro to create new datasets while adding a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-up-macro-to-create-new-datasets-while-adding-a-new-variable/m-p/875315#M345855</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rcstall;
	set lcmf.cm20&amp;amp;fy1two.01a (keep=UCI RCAbrv Status)
              lcmf.cm20&amp;amp;fy2two.01a (keep=UCI RCAbrv Status)
              lcmf.cm20&amp;amp;fy3two.01a (keep=UCI RCAbrv Status)
              lcmf.cm20&amp;amp;fy4two.01a (keep=UCI RCAbrv Status)
                    INDSNAME = src;

*can use text operations to parse this to desired format;
fy = src;

where status in ('1', '2');

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 18:06:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-up-macro-to-create-new-datasets-while-adding-a-new-variable/m-p/875315#M345855</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2023-05-11T18:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: Set up macro to create new datasets while adding a new variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Set-up-macro-to-create-new-datasets-while-adding-a-new-variable/m-p/875328#M345859</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;&amp;nbsp;this works perfectly!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 May 2023 18:49:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Set-up-macro-to-create-new-datasets-while-adding-a-new-variable/m-p/875328#M345859</guid>
      <dc:creator>kevsma</dc:creator>
      <dc:date>2023-05-11T18:49:41Z</dc:date>
    </item>
  </channel>
</rss>

