<?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: Conditionally move the files based on macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705157#M216253</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I’ve the table as shown below. I want to conditionally move the file(s) based on the value from this table and also the file name. File name will be like ‘INS_GT_1_0417.csv’.From this file name I’ve to find the last four digits and compare it to the field (PARAM_VLU) from the table below. If it matches, I’ve to move the file from one folder to another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;FUNCTION&amp;nbsp;&amp;nbsp; PARAM_VLU&lt;/STRONG&gt;&lt;BR /&gt;GTA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0417&lt;BR /&gt;GTA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0437&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We already had this concept before in our project and in those days there will be only one record for each function. Now we’re going to have more than 1 record for each function. For example, if the keep the file, ‘INS_GT_1_0437.csv’ then the program should check the last four digits and compare it with the table and move the file if value matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As there are more than one record for the same function, I find struggle to get it moved. If there is two files in source folder, then we have to both the files target folder if value matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below are my previous version of the code which was used. Now I’m trying to update the program but I’m not getting the desired results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/*Previous version*/

/*Macro variable to store value*/
%let entity_nl=; 
 
proc sql noprint;
    select  t1.param_vlu into: entity_nl trimmed
      from  BFSI.reference t1
     where  t1.function = 'GTA';
quit;

%put ##### GTA: &amp;amp;entity_nl. #####;

/*File Movement based on condition below*/

%if &amp;amp;function.=GTA and
    %index(&amp;amp;file_name.,&amp;amp;entity_nl.) &amp;gt; 0 
    %then
    %do;
        
        %let _loop=%eval(&amp;amp;_loop. + 1);
...
...
&amp;lt;code for file movement&amp;gt;
...
...
%end;

/*current version which I'm trying to update*/
%let entity_nl=; 
 
proc sql noprint;
    select  t1.param_vlu into: entity_nl separated by ","
      from  BFSI.reference t1
     where  t1.function = 'GTA';
quit;

%put ##### GTA: &amp;amp;entity_nl. #####;
&lt;/PRE&gt;
&lt;P&gt;In the current version, macro variable ‘entity_nl’ resolves to (0417,0437), so the index function from the ‘file movement’ program which I placed above won’t work as it receives too many arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know how to tweak the file movement program to work for two files (0417 and 0437) in source folder or if macro variable (entity_nl) resolves to two values (0417,0437) but only one file (either 0417 or 0437 file) has been kept in source folder&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;To do long story short, please try next code:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    create table params as
    select  distinct param_vlu 
      from  BFSI.reference 
     where  function = 'GTA';
quit;

%macro move(entity_nl,file_name);
      /* execute your code to move file &amp;amp;file_name */
	  ......
%mend move;

data _null_;
 set params;
     file_name = cats("&amp;amp;dir./INS_GT_1_",trim(param_vlu),".csv");
	 if fileexist(file_name) then do;
	    call execute('%nrstr(%move('!!param_vlu!!','!!filename!!'));');
	 end;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;Note - code was edited and corrected according to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;post.&lt;/P&gt;</description>
    <pubDate>Fri, 11 Dec 2020 05:51:34 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2020-12-11T05:51:34Z</dc:date>
    <item>
      <title>Conditionally move the files based on macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705017#M216179</link>
      <description>&lt;P&gt;I’ve the table as shown below. I want to conditionally move the file(s) based on the value from this table and also the file name. File name will be like ‘INS_GT_1_0417.csv’.From this file name I’ve to find the last four digits and compare it to the field (PARAM_VLU) from the table below. If it matches, I’ve to move the file from one folder to another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;FUNCTION&amp;nbsp;&amp;nbsp; PARAM_VLU&lt;/STRONG&gt;&lt;BR /&gt;GTA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0417&lt;BR /&gt;GTA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0437&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We already had this concept before in our project and in those days there will be only one record for each function. Now we’re going to have more than 1 record for each function. For example, if the keep the file, ‘INS_GT_1_0437.csv’ then the program should check the last four digits and compare it with the table and move the file if value matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As there are more than one record for the same function, I find struggle to get it moved. If there is two files in source folder, then we have to both the files target folder if value matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below are my previous version of the code which was used. Now I’m trying to update the program but I’m not getting the desired results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/*Previous version*/

/*Macro variable to store value*/
%let entity_nl=; 
 
proc sql noprint;
    select  t1.param_vlu into: entity_nl trimmed
      from  BFSI.reference t1
     where  t1.function = 'GTA';
quit;

%put ##### GTA: &amp;amp;entity_nl. #####;

/*File Movement based on condition below*/

%if &amp;amp;function.=GTA and
    %index(&amp;amp;file_name.,&amp;amp;entity_nl.) &amp;gt; 0 
    %then
    %do;
        
        %let _loop=%eval(&amp;amp;_loop. + 1);
...
...
&amp;lt;code for file movement&amp;gt;
...
...
%end;

/*current version which I'm trying to update*/
%let entity_nl=; 
 
proc sql noprint;
    select  t1.param_vlu into: entity_nl separated by ","
      from  BFSI.reference t1
     where  t1.function = 'GTA';
quit;

%put ##### GTA: &amp;amp;entity_nl. #####;
&lt;/PRE&gt;
&lt;P&gt;In the current version, macro variable ‘entity_nl’ resolves to (0417,0437), so the index function from the ‘file movement’ program which I placed above won’t work as it receives too many arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know how to tweak the file movement program to work for two files (0417 and 0437) in source folder or if macro variable (entity_nl) resolves to two values (0417,0437) but only one file (either 0417 or 0437 file) has been kept in source folder&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 10:52:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705017#M216179</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-12-10T10:52:47Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally move the files based on macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705048#M216196</link>
      <description>&lt;P&gt;You are using the macro variable &lt;STRONG&gt;&amp;amp;file_name&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;In the old version you assigned &lt;STRONG&gt;one&lt;/STRONG&gt; value to that macro variable and&lt;/P&gt;
&lt;P&gt;I suppose it was:&amp;nbsp; %let file_name = INS_GT_1_0437.csv ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, as there are &lt;STRONG&gt;more than one&lt;/STRONG&gt; observation in BFSI.reference table,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;you got a &lt;STRONG&gt;list&lt;/STRONG&gt; of param values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I understand correctly you need to deal with list of file names, &lt;STRONG&gt;each will match one&lt;/STRONG&gt; param_VLU.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If possible assign a dynamic file_name as&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;STRONG&gt;%let file_name = INS_GT_1_&amp;amp;entity_nl..csv ;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope that will give you a hint how to resolve your issue.&lt;/P&gt;
&lt;P&gt;It seems to me that there is no enough information to let you a complete answer,&lt;/P&gt;
&lt;P&gt;like: have all files' names the format ?! or is it possible to have PARAM_VLU without a&amp;nbsp; matching file ?!&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 13:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705048#M216196</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-10T13:58:11Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally move the files based on macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705067#M216203</link>
      <description>&lt;P&gt;Files will be placed by customers. Sometime they keep the all the files (0417, 0437)&amp;nbsp;which has the digits matching with 'PARAM_VLU' from the table (0417, 0437)&amp;nbsp;and sometimes they keep only few files (0417)&amp;nbsp;which will match with the table (0417, 0437)&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 14:27:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705067#M216203</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-12-10T14:27:00Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally move the files based on macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705069#M216204</link>
      <description>&lt;P&gt;Read the filenames as I've shown you in your other thread, extract the digits, and join with your parameter dataset. Then move the matches.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 14:30:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705069#M216204</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-10T14:30:00Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally move the files based on macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705157#M216253</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I’ve the table as shown below. I want to conditionally move the file(s) based on the value from this table and also the file name. File name will be like ‘INS_GT_1_0417.csv’.From this file name I’ve to find the last four digits and compare it to the field (PARAM_VLU) from the table below. If it matches, I’ve to move the file from one folder to another.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;FUNCTION&amp;nbsp;&amp;nbsp; PARAM_VLU&lt;/STRONG&gt;&lt;BR /&gt;GTA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0417&lt;BR /&gt;GTA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0437&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;We already had this concept before in our project and in those days there will be only one record for each function. Now we’re going to have more than 1 record for each function. For example, if the keep the file, ‘INS_GT_1_0437.csv’ then the program should check the last four digits and compare it with the table and move the file if value matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As there are more than one record for the same function, I find struggle to get it moved. If there is two files in source folder, then we have to both the files target folder if value matches.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below are my previous version of the code which was used. Now I’m trying to update the program but I’m not getting the desired results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;/*Previous version*/

/*Macro variable to store value*/
%let entity_nl=; 
 
proc sql noprint;
    select  t1.param_vlu into: entity_nl trimmed
      from  BFSI.reference t1
     where  t1.function = 'GTA';
quit;

%put ##### GTA: &amp;amp;entity_nl. #####;

/*File Movement based on condition below*/

%if &amp;amp;function.=GTA and
    %index(&amp;amp;file_name.,&amp;amp;entity_nl.) &amp;gt; 0 
    %then
    %do;
        
        %let _loop=%eval(&amp;amp;_loop. + 1);
...
...
&amp;lt;code for file movement&amp;gt;
...
...
%end;

/*current version which I'm trying to update*/
%let entity_nl=; 
 
proc sql noprint;
    select  t1.param_vlu into: entity_nl separated by ","
      from  BFSI.reference t1
     where  t1.function = 'GTA';
quit;

%put ##### GTA: &amp;amp;entity_nl. #####;
&lt;/PRE&gt;
&lt;P&gt;In the current version, macro variable ‘entity_nl’ resolves to (0417,0437), so the index function from the ‘file movement’ program which I placed above won’t work as it receives too many arguments.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I would like to know how to tweak the file movement program to work for two files (0417 and 0437) in source folder or if macro variable (entity_nl) resolves to two values (0417,0437) but only one file (either 0417 or 0437 file) has been kept in source folder&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;STRONG&gt;To do long story short, please try next code:&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
    create table params as
    select  distinct param_vlu 
      from  BFSI.reference 
     where  function = 'GTA';
quit;

%macro move(entity_nl,file_name);
      /* execute your code to move file &amp;amp;file_name */
	  ......
%mend move;

data _null_;
 set params;
     file_name = cats("&amp;amp;dir./INS_GT_1_",trim(param_vlu),".csv");
	 if fileexist(file_name) then do;
	    call execute('%nrstr(%move('!!param_vlu!!','!!filename!!'));');
	 end;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;Note - code was edited and corrected according to&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;post.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Dec 2020 05:51:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705157#M216253</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-11T05:51:34Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally move the files based on macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705161#M216255</link>
      <description>&lt;P&gt;Your CALL EXECUTE should look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call execute('%nrstr(%move('!!param_vlu!!','!!filename!!'));');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Single quotes, so that the macro triggers are not resolved when&amp;nbsp;&lt;EM&gt;this&lt;/EM&gt; data step is compiled, and %NRSTR to prevent premature execution of macro statements in the macro.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 18:28:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705161#M216255</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2020-12-10T18:28:13Z</dc:date>
    </item>
    <item>
      <title>Re: Conditionally move the files based on macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705191#M216266</link>
      <description>&lt;P&gt;Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp; for the correction and the explanation.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Dec 2020 19:37:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditionally-move-the-files-based-on-macro-variable/m-p/705191#M216266</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2020-12-10T19:37:58Z</dc:date>
    </item>
  </channel>
</rss>

