<?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 design dynamic data step to generate multiple datasets using macro varialbes? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673144#M202444</link>
    <description>&lt;P&gt;Apart from the documentation for CALL EXECUTE, which &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;already linked to, the use of %NRSTR is important. It prevents premature execution of macro code when the instructions are fed to the execution queue, and is usually a good idea when calling a macro with CALL EXECUTE.&lt;/P&gt;</description>
    <pubDate>Wed, 29 Jul 2020 14:23:55 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2020-07-29T14:23:55Z</dc:date>
    <item>
      <title>How to design dynamic data step to generate multiple datasets using macro varialbes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673079#M202407</link>
      <description>&lt;P&gt;I want to generate multiple datasets dynamically and automatically using macro variable reference.&lt;BR /&gt;The basic idea is to use the elements of below list as iterators:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;libname lsa 'C:\Users\mayqy015\Desktop\SAS Holder\loan_size_analysis';

%let 
codelist
=
_beijing
_tianjin
...
_hongkong
_macao
;&lt;/PRE&gt;&lt;P&gt;These iterators will become the key part of dynamic referencing, and here below are the following codes:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;%macro covid19trimming(code);

data lsa.&amp;amp;code._COVID19_treated; 
set lsa.&amp;amp;code; 
if project_opentime_cn&amp;lt;20200101 then delete; 
if project_opentime_cn&amp;gt;20200331 then delete; 
run;
%mend;

%macro try;
	%let word_cnt=%sysfunc(countw(&amp;amp;codelist));
	%do i = 1 %to &amp;amp;word_cnt;
		%let code=%qscan(%bquote(&amp;amp;codelist),&amp;amp;i);
		%covid19trimming(&amp;amp;code);
	%end;
%mend;

%try;&lt;/PRE&gt;&lt;P&gt;Unfortunately, even though the code can be run without mistakes, the SAS system cannot recognize my data step correctly. For example:&lt;/P&gt;&lt;PRE&gt;NOTE: There were 54752 observations read from the data set LSA._BEIJING.
NOTE: The data set LSA._BEIJING has 54752 observations and 80 variables.
NOTE: The data set WORK._COVID19_TREATED has 54752 observations and 80 variables.
NOTE: DATA statement used (Total process time):
      real time           2.40 seconds
      cpu time            0.57 seconds&lt;/PRE&gt;&lt;P&gt;My opinion is that the SAS system recognizes that there are two datasets to be created, LSA._BEIJING and _COVID19_TREATED.&lt;BR /&gt;But I actually want to create only ONE dataset named 'LSA._BEIJING_COVID19_TREATED'.&lt;BR /&gt;Can any kind and generous experts help me out?&lt;BR /&gt;&lt;BR /&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 10:35:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673079#M202407</guid>
      <dc:creator>applemonster</dc:creator>
      <dc:date>2020-07-29T10:35:36Z</dc:date>
    </item>
    <item>
      <title>Re: How to design dynamic data step to generate multiple datasets using macro varialbes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673080#M202408</link>
      <description>&lt;P&gt;Maybe:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data lsa.%unquote(&amp;amp;code.)_COVID19_treated; &lt;/PRE&gt;
&lt;P&gt;will help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 10:39:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673080#M202408</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-29T10:39:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to design dynamic data step to generate multiple datasets using macro varialbes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673081#M202409</link>
      <description>&lt;P&gt;or maybe this:&lt;/P&gt;
&lt;PRE&gt;%macro covid19trimming(code);
%let code = &amp;amp;code.; /* to remove spaces */
data lsa.&amp;amp;code._COVID19_treated;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jul 2020 10:40:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673081#M202409</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-29T10:40:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to design dynamic data step to generate multiple datasets using macro varialbes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673082#M202410</link>
      <description>&lt;P&gt;Store your codes in a dataset, and use that to call the macro repeatedly:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data control;
input code $20.;
datalines;
_beijing
_tianjin
_hongkong
_macao
;

data _null_;
set control;
call execute('%nrstr(%covid19trimming(' !! trim(code) !! '))');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jul 2020 10:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673082#M202410</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-29T10:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to design dynamic data step to generate multiple datasets using macro varialbes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673090#M202417</link>
      <description>&lt;P&gt;Yes! It works! But I still do not know why. I cannot quite understand SAS masking. Could you please explain a little bit? Or do you have some material that I can learn? Thank you so much for your generous help!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 12:10:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673090#M202417</guid>
      <dc:creator>applemonster</dc:creator>
      <dc:date>2020-07-29T12:10:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to design dynamic data step to generate multiple datasets using macro varialbes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673092#M202419</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My favourite reading about macroquotting:&amp;nbsp;&lt;A href="https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt185.pdf" target="_blank"&gt;https://stats.idre.ucla.edu/wp-content/uploads/2016/02/bt185.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In your code you used %qscan() which not only scanned but also macroquotted scanned text and some "quitting leftovers" left attached to value of&amp;nbsp;&amp;amp;code.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I may suggest something, the golden rule of macroquotting is:&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;"If you can do something with macroquoting or without macroquoting then do it &lt;STRONG&gt;without&lt;/STRONG&gt; macroquoting",&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;so consider solution proposed by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 12:22:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673092#M202419</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-29T12:22:20Z</dc:date>
    </item>
    <item>
      <title>Re: How to design dynamic data step to generate multiple datasets using macro varialbes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673096#M202422</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code is clean and tidy, but it is so far away from what I have learnt than I cannot understand. So could you please suggest some reference to videos and articles that I can learn your way?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 12:34:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673096#M202422</guid>
      <dc:creator>applemonster</dc:creator>
      <dc:date>2020-07-29T12:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: How to design dynamic data step to generate multiple datasets using macro varialbes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673111#M202429</link>
      <description>&lt;P&gt;To understand Kurt's code I would suggest to start with reading about call execute() routine:&lt;/P&gt;
&lt;P&gt;1) a blog:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/sgf/2017/08/02/call-execute-for-sas-data-driven-programming/" target="_blank"&gt;https://blogs.sas.com/content/sgf/2017/08/02/call-execute-for-sas-data-driven-programming/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;2) an article:&amp;nbsp;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi22/CODERS/PAPER70.PDF" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi22/CODERS/PAPER70.PDF&lt;/A&gt;&amp;nbsp;(by guru Ian Whitlock)&lt;/P&gt;
&lt;P&gt;3) the doc:&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1q1527d51eivsn1ob5hnz0yd1hx.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en"&gt;https://documentation.sas.com/?docsetId=mcrolref&amp;amp;docsetTarget=n1q1527d51eivsn1ob5hnz0yd1hx.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;All the best&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 13:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673111#M202429</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-07-29T13:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to design dynamic data step to generate multiple datasets using macro varialbes?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673144#M202444</link>
      <description>&lt;P&gt;Apart from the documentation for CALL EXECUTE, which &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;already linked to, the use of %NRSTR is important. It prevents premature execution of macro code when the instructions are fed to the execution queue, and is usually a good idea when calling a macro with CALL EXECUTE.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Jul 2020 14:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-design-dynamic-data-step-to-generate-multiple-datasets/m-p/673144#M202444</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-07-29T14:23:55Z</dc:date>
    </item>
  </channel>
</rss>

