<?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: Using macro variable for partial dataset name does not work with background submission in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742908#M232485</link>
    <description>&lt;P&gt;Actually, had to write the above like this, so that the correct filename is passed to the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set mcdtemp.mc_files;
	call execute('%nrstr(%parse_datafiles('||filename||'));');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Fri, 21 May 2021 14:39:07 GMT</pubDate>
    <dc:creator>ojaro</dc:creator>
    <dc:date>2021-05-21T14:39:07Z</dc:date>
    <item>
      <title>Using macro variable for partial dataset name does not work with background submission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742810#M232433</link>
      <description>&lt;P&gt;Hi experts,&lt;/P&gt;
&lt;P&gt;I am using the following code in SASStudioV (Viya 3.5) to read list of datasets within my library and then dynamically loop through them and append the data to the master table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql /*noprint*/;
	  create table mcdtemp.enumtables as
	  select memname
	  from dictionary.tables
	  where libname = 'JSONDATA'
	  and memname not like ('ROOT')
	  and memname not like ('ALLDATA')
	  and memname not like ('DOCS');
	quit;
	
	data mcdtemp.enumtables;
		set mcdtemp.enumtables;
		enum_type=strip(substr(memname,6));
		drop memname;
	run;

	proc sql /*noprint*/;   
		select enum_type      
		into :mc_enum_ts
		separated by ' '
		from mcdtemp.enumtables;   
	quit;

	%let enumCount = %sysfunc(countw(&amp;amp;mc_enum_ts.,' '));
	%do i=1 %to &amp;amp;enumCount;
	
		%let mc_enumt=%scan(&amp;amp;mc_enum_ts.,&amp;amp;i.,' ');
		
		data mcdtemp.enumdata_temp;
		set jsondata.docs_&amp;amp;mc_enumt.;
		enum_type="&amp;amp;mc_enumt.";
		array j &amp;amp;mc_enumt.1-&amp;amp;mc_enumt.100;
			do over j;
			value=compress(j);
			output;
		end;
	
		keep ordinal_docs enum_type value;
	run;
	
	data mcdtemp.enumdata_temp;
		set mcdtemp.enumdata_temp;
		
		if missing(value) or trim(value)='' then delete;
	
		doc_id=ordinal_docs + put(&amp;amp;mc_page_c.,3.) * 10000;
		drop ordinal_docs;
	run;
	
	proc append base=mcdtemp.&amp;amp;mc_doc_enum_table data=mcdtemp.enumdata_temp force;
	
	%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code seems to be working fine when I am testing it by running it in SASStudioV. However, when I try to do a background submission, to see how the code would run as a scheduled job, I get weird error referencing to work library (please see the error below) even if I am not using it anywhere in my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;source: data mcdtemp.enumdata_temp;   set
source: 5    + jsondata.docs_&amp;amp;mc_enum_ts.;   enum_type="&amp;amp;mc_enum_ts.";   array j &amp;amp;mc_enum_ts.1-&amp;amp;mc_enum_ts.100;    do over j;    
source: value=compress(j);    output;   end;     keep ordinal_docs enum_type value;  run;    data mcdtemp.enumdata_temp;   set 
source: mcdtemp.enumdata_temp
error: ERROR: File WORK.DOMAIN_NAME.DATA does not exist.
error: ERROR: File WORK.EMAIL.DATA does not exist.
error: ERROR: File WORK.HASHTAG.DATA does not exist.
error: ERROR: File WORK.HASHTAG_LC.DATA does not exist.
error: ERROR: File WORK.INFORMATION_CONTEXT.DATA does not exist.
error: ERROR: File WORK.KEYWORDS.DATA does not exist.
error: ERROR: File WORK.MEDIA.DATA does not exist.
error: ERROR: File WORK.META_SPKID.DATA does not exist.
error: ERROR: File WORK.PERSON_DETECTED.DATA does not exist.
error: ERROR: File WORK.RECIPIENT.DATA does not exist.
error: ERROR: File WORK.URL.DATA does not exist.
error: ERROR: Alphabetic prefixes for enumerated variables (URL1-CHILDREN_UID) are different.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also note that the error message is stating that I am using macro variable &lt;CODE class=" language-sas"&gt;mc_enum_ts&lt;/CODE&gt; in order to generate the dataset name (&lt;CODE class=" language-sas"&gt;jsondata.docs_&amp;amp;mc_enum_ts.&lt;/CODE&gt;), but as you can see from my code above, I am using macro variable &lt;CODE class=" language-sas"&gt;mc_enumt&lt;/CODE&gt; for this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any suggestions what might be going wrong here?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Olli&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 00:56:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742810#M232433</guid>
      <dc:creator>ojaro</dc:creator>
      <dc:date>2021-05-21T00:56:32Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variable for partial dataset name does not work with background submission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742818#M232436</link>
      <description>&lt;P&gt;Those errors make it look like the macro variable has spaces in it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you have different settings for the VALIDVARNAMES option in the two environments?&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 03:03:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742818#M232436</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-21T03:03:27Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variable for partial dataset name does not work with background submission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742837#M232445</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks for your reply.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Yes. macro variable mc_enum_ts has spaces in it, so the error message makes sense that way, since according to log I am trying to use it like this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set jsondata.docs_&amp;amp;mc_enum_ts.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;However, my code is using another macro variable for the statement that creates the error:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;set jsondata.docs_&amp;amp;mc_enumt.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;which is derived from mc_enum_ts like this(by splitting the valiable to multiple values using space as the separator):&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let enumCount = %sysfunc(countw(&amp;amp;mc_enum_ts.,' '));
	%do i=1 %to &amp;amp;enumCount;
	
		%let mc_enumt=%scan(&amp;amp;mc_enum_ts.,&amp;amp;i.,' ');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It looks like SAS is changing my code on the execution or something?&lt;BR /&gt;&lt;BR /&gt;Best regards,&lt;BR /&gt;&lt;BR /&gt;Olli&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 07:31:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742837#M232445</guid>
      <dc:creator>ojaro</dc:creator>
      <dc:date>2021-05-21T07:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variable for partial dataset name does not work with background submission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742842#M232450</link>
      <description>&lt;P&gt;Ok, I managed to figure it out.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;My code is running in a macro and I am calling the macro with call execute. Apparently this does not work if you want to populate macro variable inside your main macro with proc sql. &lt;BR /&gt;&lt;BR /&gt;The solution is to use %nrstr as part of call execute as below:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    set mcdtemp.mc_files;
    call symput("mc_file",strip(filename));
    call execute('%nrstr(%parse_datafiles);');
run; &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is more about this issue at &lt;A href="https://stackoverflow.com/questions/50453908/proc-sql-select-into-does-not-create-macro-variable" target="_blank"&gt;https://stackoverflow.com/questions/50453908/proc-sql-select-into-does-not-create-macro-variable&lt;/A&gt;.&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 08:15:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742842#M232450</guid>
      <dc:creator>ojaro</dc:creator>
      <dc:date>2021-05-21T08:15:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variable for partial dataset name does not work with background submission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742908#M232485</link>
      <description>&lt;P&gt;Actually, had to write the above like this, so that the correct filename is passed to the macro:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set mcdtemp.mc_files;
	call execute('%nrstr(%parse_datafiles('||filename||'));');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 May 2021 14:39:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742908#M232485</guid>
      <dc:creator>ojaro</dc:creator>
      <dc:date>2021-05-21T14:39:07Z</dc:date>
    </item>
    <item>
      <title>Re: Using macro variable for partial dataset name does not work with background submission</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742913#M232487</link>
      <description>&lt;P&gt;Typically you do not need (or want) to add macro quoting to the parameter values also.&amp;nbsp; Just the macro call.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also using the CATS() function to help generate the string to pass to CALL EXECUTE() will automatically trim the trailing spaces from the values of FILENAME variable.&amp;nbsp; If nothing else it will make the SAS log easier to read.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  set mcdtemp.mc_files;
  call execute(cats('%nrstr(%parse_datafiles)(',filename,');'));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 21 May 2021 14:56:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-macro-variable-for-partial-dataset-name-does-not-work-with/m-p/742913#M232487</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-21T14:56:44Z</dc:date>
    </item>
  </channel>
</rss>

