<?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 How do I load data using macro loop in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-load-data-using-macro-loop/m-p/555374#M9662</link>
    <description>&lt;P&gt;I have files on a server in the following naming convention.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;prefixtest.123.YYYYMM&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;prefixtest.223.YYYYMM&lt;/LI&gt;&lt;LI&gt;...&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;There are many files on the server, so I would like to read them in by sample. I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;Macro runparallel:&amp;nbsp; loops through SampleCodeLst and SampleLst to get the number of samples we have. This macro then calls macro load_data.&lt;/P&gt;&lt;P&gt;Macro load_data: tries to set data to "&amp;amp;prefixtest.&amp;amp;samplecode.." It uses a semi colon to generalize all the monthly file suffixes. It also specifies the variable via macro variable vlist.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let iLoc =InputFileLocation;
%let oLoc =OutputFileLocation;
%let SampleCodeLst = 123 223; 
%let SampleLst = Sample1 Sample2; 
%let vLst = AccountIdentifier Period ImportantVar;
%let fileprefix = prefixtest; 

%syslput iLoc=%bquote(&amp;amp;iLoc.);
%syslput oLoc=%bquote(&amp;amp;oLoc.);
%syslput vLst=%bquote(&amp;amp;vLst.);
%syslput fileprefix=%bquote(&amp;amp;fileprefix.);

%macro load_data(SampleCode=, Sample=,gsession=);

	%syslput SampleCode=%bquote(&amp;amp;SampleCode.);
	%syslput Sample=%bquote(&amp;amp;Sample.);

	signon &amp;amp;gsession.;
	%put SESSION &amp;amp;gsession. STARTING;

	rsubmit gsession connectwait=no connectpersist=no sysrputsync=yes;
		libname iLoc "&amp;amp;iLoc." access=readonly; run;
		libname oLoc "&amp;amp;oLoc." compress=binary; run;

		data oLoc.&amp;amp;Sample.;
			set &amp;amp;fileprefix.&amp;amp;SampleCode.:(keep= &amp;amp;vLst.)
		run;

endrsubmit;
%mend load_data;

%macro runparallel;
	waitfor _all_
	%do Loop=1 %to %sysfunc(countw(&amp;amp;SampleLst, ' '));
		%Let SampleCode = %sysfunc(scan(&amp;amp;SampleCodeLst,&amp;amp;Loop.,' '));
		%Let Sample = %sysfunc(scan(&amp;amp;SampleLst,&amp;amp;Loop.,' '));
		%load_data(SampleCode=&amp;amp;SampleCode., Sample=&amp;amp;Sample.,gsession=g1_&amp;amp;Loop.);
	%end;
	;
%mend runparallel;
%runparallel; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Two Issues occurs:&lt;/P&gt;&lt;P&gt;1) Run parallel&amp;nbsp; macro: Looping may or may not be an issue. I'm not sure why load_data is not called twice in my scenario. It might be the way I am passing macro variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) load data macro: The "set" data line does not appear to be working at all. See below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "SAMPLECODE".&lt;BR /&gt;prefixtest_123&lt;BR /&gt;ERROR: File prefixtest.DATA does not exist....&lt;/P&gt;</description>
    <pubDate>Wed, 01 May 2019 15:00:01 GMT</pubDate>
    <dc:creator>d0021</dc:creator>
    <dc:date>2019-05-01T15:00:01Z</dc:date>
    <item>
      <title>How do I load data using macro loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-load-data-using-macro-loop/m-p/555374#M9662</link>
      <description>&lt;P&gt;I have files on a server in the following naming convention.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;prefixtest.123.YYYYMM&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;prefixtest.223.YYYYMM&lt;/LI&gt;&lt;LI&gt;...&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;There are many files on the server, so I would like to read them in by sample. I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;Macro runparallel:&amp;nbsp; loops through SampleCodeLst and SampleLst to get the number of samples we have. This macro then calls macro load_data.&lt;/P&gt;&lt;P&gt;Macro load_data: tries to set data to "&amp;amp;prefixtest.&amp;amp;samplecode.." It uses a semi colon to generalize all the monthly file suffixes. It also specifies the variable via macro variable vlist.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let iLoc =InputFileLocation;
%let oLoc =OutputFileLocation;
%let SampleCodeLst = 123 223; 
%let SampleLst = Sample1 Sample2; 
%let vLst = AccountIdentifier Period ImportantVar;
%let fileprefix = prefixtest; 

%syslput iLoc=%bquote(&amp;amp;iLoc.);
%syslput oLoc=%bquote(&amp;amp;oLoc.);
%syslput vLst=%bquote(&amp;amp;vLst.);
%syslput fileprefix=%bquote(&amp;amp;fileprefix.);

%macro load_data(SampleCode=, Sample=,gsession=);

	%syslput SampleCode=%bquote(&amp;amp;SampleCode.);
	%syslput Sample=%bquote(&amp;amp;Sample.);

	signon &amp;amp;gsession.;
	%put SESSION &amp;amp;gsession. STARTING;

	rsubmit gsession connectwait=no connectpersist=no sysrputsync=yes;
		libname iLoc "&amp;amp;iLoc." access=readonly; run;
		libname oLoc "&amp;amp;oLoc." compress=binary; run;

		data oLoc.&amp;amp;Sample.;
			set &amp;amp;fileprefix.&amp;amp;SampleCode.:(keep= &amp;amp;vLst.)
		run;

endrsubmit;
%mend load_data;

%macro runparallel;
	waitfor _all_
	%do Loop=1 %to %sysfunc(countw(&amp;amp;SampleLst, ' '));
		%Let SampleCode = %sysfunc(scan(&amp;amp;SampleCodeLst,&amp;amp;Loop.,' '));
		%Let Sample = %sysfunc(scan(&amp;amp;SampleLst,&amp;amp;Loop.,' '));
		%load_data(SampleCode=&amp;amp;SampleCode., Sample=&amp;amp;Sample.,gsession=g1_&amp;amp;Loop.);
	%end;
	;
%mend runparallel;
%runparallel; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Two Issues occurs:&lt;/P&gt;&lt;P&gt;1) Run parallel&amp;nbsp; macro: Looping may or may not be an issue. I'm not sure why load_data is not called twice in my scenario. It might be the way I am passing macro variables.&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) load data macro: The "set" data line does not appear to be working at all. See below.&amp;nbsp;&lt;/P&gt;&lt;P&gt;NOTE: Line generated by the macro variable "SAMPLECODE".&lt;BR /&gt;prefixtest_123&lt;BR /&gt;ERROR: File prefixtest.DATA does not exist....&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 15:00:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-load-data-using-macro-loop/m-p/555374#M9662</guid>
      <dc:creator>d0021</dc:creator>
      <dc:date>2019-05-01T15:00:01Z</dc:date>
    </item>
    <item>
      <title>Re: How do I load data using macro loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-load-data-using-macro-loop/m-p/555376#M9664</link>
      <description>&lt;P&gt;Blanks are the default delimiters for countw and scan functions, so they need not (and in your case must not) be specified.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do Loop=1 %to %sysfunc(countw(&amp;amp;SampleLst));
	%Let SampleCode = %sysfunc(scan(&amp;amp;SampleCodeLst,&amp;amp;Loop.));
	%Let Sample = %sysfunc(scan(&amp;amp;SampleLst,&amp;amp;Loop.));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 May 2019 15:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-load-data-using-macro-loop/m-p/555376#M9664</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-05-01T15:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: How do I load data using macro loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-load-data-using-macro-loop/m-p/555377#M9665</link>
      <description>&lt;P&gt;You say that your files have this naming convention:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;prefixtest.123.YYYYMM&amp;nbsp;&lt;/LI&gt;
&lt;LI&gt;prefixtest.223.YYYYMM&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;I do not see anything in our code that attempts to add a YYYYMM portion.&lt;/P&gt;
&lt;P&gt;The message&lt;/P&gt;
&lt;PRE&gt;NOTE: Line generated by the macro variable "SAMPLECODE".
prefixtest_123
ERROR: File prefixtest.DATA does not exist....&lt;/PRE&gt;
&lt;P&gt;Indicates that you generated prefixtest&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;_&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;123 &lt;STRONG&gt;not &lt;/STRONG&gt; prefixtest&lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#ff0000"&gt;.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;123 that you say are the file names in addition to not having the YYYYMM bit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 15:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-load-data-using-macro-loop/m-p/555377#M9665</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-05-01T15:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: How do I load data using macro loop</title>
      <link>https://communities.sas.com/t5/New-SAS-User/How-do-I-load-data-using-macro-loop/m-p/555398#M9670</link>
      <description>&lt;P&gt;The order of these statements seems backwards. How can you push a value to a macro variable in a remote session you haven't started yet?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	%syslput SampleCode=%bquote(&amp;amp;SampleCode.);
	%syslput Sample=%bquote(&amp;amp;Sample.);

	signon &amp;amp;gsession.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Personally I have had issues with the new %SYSLPUT macro statement and have frequently gone back to using the old %SYSLPUT() macro that SAS used to supply.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is link to a version in GITHUB,&amp;nbsp; Name is changed to %SYSLPUT612() , since you cannot make a macro with the same name as a macro function.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/sasutils/macros/blob/master/syslput612.sas" target="_blank"&gt;https://github.com/sasutils/macros/blob/master/syslput612.sas&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 May 2019 16:31:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/How-do-I-load-data-using-macro-loop/m-p/555398#M9670</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-05-01T16:31:38Z</dc:date>
    </item>
  </channel>
</rss>

