<?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 use array to pass information , assign two libraries and copy some datasets from src1 to in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762196#M39347</link>
    <description>&lt;P&gt;You don't seem to understand how CALL EXECUTE() works and when the generated code works.&amp;nbsp; That is another reason to use the write a file method.&amp;nbsp; You are much less likely to get confused about when the generated code will run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would probably be easier to create a macro that confirms the list of files before trying to copy them.&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro copy_members(inlib,outlib,memlist);
proc sql noprint;
select nliteral(memname) into :memlist separated by ' '
from dictionary.members
where libname="%upcase(&amp;amp;inlib)"
  and memtype='DATA'
  and findw("&amp;amp;memlist",memname,' ','sit')
;
quit;
%if &amp;amp;sqlobs %then %do; 
proc copy inlib=&amp;amp;inlib outlib=&amp;amp;outlib memtype=data;
   select &amp;amp;memlist ;
run;
%end;

%mend copy_members;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example usage:&lt;/P&gt;
&lt;PRE&gt;332   options mprint;
333   %copy_members(inlib=sashelp,outlib=work,memlist=cars class xyz);
MPRINT(COPY_MEMBERS):   proc sql noprint;
MPRINT(COPY_MEMBERS):   select nliteral(memname) into :memlist separated by ' ' from dictionary.members where libname="SASHELP" and
memtype='DATA' and findw("cars class xyz",memname,' ','sit') ;
MPRINT(COPY_MEMBERS):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.04 seconds


MPRINT(COPY_MEMBERS):   proc copy inlib=sashelp outlib=work memtype=data;
MPRINT(COPY_MEMBERS):   select CARS CLASS ;
MPRINT(COPY_MEMBERS):   run;

NOTE: Copying SASHELP.CARS to WORK.CARS (memtype=DATA).
NOTE: There were 428 observations read from the data set SASHELP.CARS.
NOTE: The data set WORK.CARS has 428 observations and 15 variables.
NOTE: Copying SASHELP.CLASS to WORK.CLASS (memtype=DATA).
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
NOTE: PROCEDURE COPY used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;</description>
    <pubDate>Tue, 17 Aug 2021 23:12:04 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-08-17T23:12:04Z</dc:date>
    <item>
      <title>how to use array to pass information , assign two libraries and copy some datasets from src1 to dest</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761909#M39325</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I would like to do, is to put some information into arrays then retreive this information, to assign two libraries , one src1 and one dest1 (there path will change into the loop), then copy a list of dataset from src1 to dest1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Does someone can help me with my code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let path1=FOLDER1;&lt;BR /&gt;%let path2=FOLDER2;&lt;BR /&gt;data _null_;&lt;BR /&gt;length folderpath1 folderpath2 $60 fname $20 L 3.;&lt;BR /&gt;array ld {9} $8 ('20210729' '20210730' '20210731' '20210801' '20210802' '20210803' '20210804' '20210805' '20210806');&lt;BR /&gt;array lcp {5} $2 ('A' 'B' 'C' 'D' 'E');&lt;BR /&gt;array bc {2} $4 ('auto' 'habi');&lt;BR /&gt;do i=1 to dim(lcp);*do i=1 to 5;&lt;/P&gt;
&lt;P&gt;if lcp(i) in ('A','B') then L=1;&lt;BR /&gt;else L=2;&lt;BR /&gt;put L;&lt;BR /&gt;do j=1 to L;*do j=1 to 2;&lt;BR /&gt;folderpath1="&amp;amp;path1."||'/'||lcp(i)||'/'||bc(j);&lt;BR /&gt;folderpath2="&amp;amp;path2."||'/'||lcp(i)||'/'||bc(j);&lt;/P&gt;
&lt;P&gt;put folderpath1;&lt;BR /&gt;put folderpaht2;&lt;/P&gt;
&lt;P&gt;/******* assign two libraries ****/&lt;BR /&gt;/* libname src1 spde folderpath1;*/&lt;BR /&gt;/* libname dest1 spde folderpath2;*/&lt;BR /&gt;/*********************************/&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;do k=1 to dim(ld);*do k=1 to 9;&lt;/P&gt;
&lt;P&gt;fname= lcp(i)||bc(j)||'_prm_d'||ld(k);&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;put fname;&lt;BR /&gt;/* copy a some datasets from src1 to dest1*/&lt;BR /&gt;/*&lt;BR /&gt;proc datasets lib=scr1;&lt;BR /&gt;copy out=dest1 memtype=data; &lt;BR /&gt;select fname; &lt;BR /&gt;run;&lt;BR /&gt;*/ &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 20:06:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761909#M39325</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-16T20:06:36Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761910#M39326</link>
      <description>libname function + CALL EXECUTE instead.</description>
      <pubDate>Mon, 16 Aug 2021 20:09:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761910#M39326</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-16T20:09:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761914#M39327</link>
      <description>&lt;P&gt;I am not sure, that I understand.&amp;nbsp; Could you please provide an example?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 20:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761914#M39327</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-16T20:27:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761916#M39328</link>
      <description>You cannot use libname statements and proc datasets in your data step. Instead, use the LIBNAME function + DOSUBL to run the proc data sets code, otherwise, generally your code should work fine.</description>
      <pubDate>Mon, 16 Aug 2021 20:29:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761916#M39328</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-16T20:29:03Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761921#M39329</link>
      <description>&lt;P&gt;May want to learn the various CAT functions.&lt;/P&gt;
&lt;P&gt;This&lt;/P&gt;
&lt;PRE&gt;folderpath1="&amp;amp;path1."||'/'||lcp(i)||'/'||bc(j);&lt;/PRE&gt;
&lt;P&gt;can be replaced with&lt;/P&gt;
&lt;PRE&gt;folderpath1=Catx('/',"&amp;amp;path1.",lcp(i),bc(j) );&lt;/PRE&gt;
&lt;P&gt;for example. The CATX function places the first parameter between all the other strings and trims trailing spaces which&amp;nbsp; may be pretty critical if you are creating or using paths for directory structures.&lt;/P&gt;
&lt;P&gt;Example, note that the Folderpath2 (spelled correctly in the PUT statement) is just the same as Folderpath1 but using the CATX function. I didn't bother to attempt to clean up the rest of the code as part of this demonstration.&lt;/P&gt;
&lt;PRE&gt;%let path1=FOLDER1;
%let path2=FOLDER2;
data _null_;
length folderpath1 folderpath2 $60 fname $20 L 3.;
array ld {9} $8 ('20210729' '20210730' '20210731' '20210801' '20210802' '20210803' '20210804' '20210805' '20210806');
array lcp {5} $2 ('A' 'B' 'C' 'D' 'E');
array bc {2} $4 ('auto' 'habi');
do i=1 to dim(lcp);

   if lcp(i) in ('A','B') then L=1;
   else L=2;
   do j=1 to L;
      folderpath1="&amp;amp;path1."||'/'||lcp(i)||'/'||bc(j);
      folderpath2=Catx('/',"&amp;amp;path1.",lcp(i),bc(j) );
      put folderpath1=;
      put folderpath2=;
   end;
end;
run;&lt;/PRE&gt;
&lt;P&gt;The || operator will use the full length of a variable and pad with blanks to meet that. Extra blanks are seldom a good idea in file path structures and if you intend to read for existing paths the values you created might not match the needed values.&lt;/P&gt;</description>
      <pubDate>Mon, 16 Aug 2021 20:35:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761921#M39329</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-16T20:35:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761946#M39333</link>
      <description>&lt;P&gt;Working off&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;code here's the rough idea. Those loops look a bit weird, and this is boing to be a PITA to debug. Personally, I do these by figuring out to do it for one set of paths. Convert that to a macro that does it for your input parameters of the file paths.&lt;/P&gt;
&lt;P&gt;Build the list of folders into a data set using the folder path methods illustrated by&amp;nbsp;@ballardW and then call the macro once for each line in your data set via call execute.&lt;A href="https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md" target="_self"&gt; I illustrate that here&lt;/A&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Otherwise, I've sketched out a bit more of the idea below. Obviously can't test this without folders/data etc which is one of the reasons I also never use this type of approach.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path1=FOLDER1;
%let path2=FOLDER2;
data _null_;
length folderpath1 folderpath2 $60 fname $20 L 3.;
array ld {9} $8 ('20210729' '20210730' '20210731' '20210801' '20210802' '20210803' '20210804' '20210805' '20210806');
array lcp {5} $2 ('A' 'B' 'C' 'D' 'E');
array bc {2} $4 ('auto' 'habi');
do i=1 to dim(lcp);

   if lcp(i) in ('A','B') then L=1;
   else L=2;
   do j=1 to L;
      folderpath1="&amp;amp;path1."||'/'||lcp(i)||'/'||bc(j);
      folderpath2=Catx('/',"&amp;amp;path1.",lcp(i),bc(j) );
      put folderpath1=;
      put folderpath2=;
     *create libname for each folder path via libname function;
     rc_src=libname('src1', folderpath1);
     rc_dest = libname('dest1', folderpath2);
     rc_complete=    dosubl('proc datasets .....rest of your code for moving files');


   end;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Aug 2021 23:46:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761946#M39333</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-16T23:46:35Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761954#M39334</link>
      <description>&lt;P&gt;Just write the code you want to generate to a file.&amp;nbsp; Then once you get it working you just use %INCLUDE to run the code.&lt;/P&gt;
&lt;P&gt;Use CATX() or CAT() to simplify constructing the names.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let path1=FOLDER1;
%let path2=FOLDER2;
filename code temp;
data _null_;
  length path file $200 ;
  array ld {9} $8 ('20210729' '20210730' '20210731' '20210801' '20210802' '20210803' '20210804' '20210805' '20210806');
  array lcp {5} $2 ('A' 'B' 'C' 'D' 'E');
  array bc {2} $4 ('auto' 'habi');
  do i=1 to dim(lcp);
    if lcp(i) in ('A','B') then L=1;
    else L=2;
    do j=1 to L;
      put ;
      path = catx('/',"&amp;amp;path1.",lcp(i),bc(j));
      put "libname src1  spde " path :$quote. ';' ;
      path = catx('/',"&amp;amp;path2.",lcp(i),bc(j));
      put "libname dest1 spde " path :$quote. ';' ;
      put 'proc datasets lib=scr1;';
      put '  copy out=dest1 memtype=data;' ;
      put '  select ' ;
      do k=1 to dim(ld);
        fname= cats(lcp(i),bc(j),'_prm_d',ld(k));
        put @5 fname ; 
      end;
      put '  ;';
      put '  run;';
      put 'quit;';
    end;
  end;
run;
%include code / source2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Also instead of the arrays you can use the power of the DO loop.&lt;/P&gt;
&lt;P&gt;Consider things like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do lcp = 'A', 'B' ,'C' ,'D' ,'E';
do date='29JUL2021'd to '06AUG2021'd;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Aug 2021 00:39:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/761954#M39334</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-17T00:39:50Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762021#M39336</link>
      <description>&lt;P&gt;So you basically want to loop over dates and copy datasets from one location to the other? You can do that with a few nested loops and the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/n10dz22b5ixohin1vwzilweetek0.htm" target="_blank" rel="noopener"&gt;FCOPY&lt;/A&gt; function.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 11:16:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762021#M39336</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-17T11:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762050#M39337</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;So you basically want to loop over dates and copy datasets from one location to the other? You can do that with a few nested loops and the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.4/lefunctionsref/n10dz22b5ixohin1vwzilweetek0.htm" target="_blank" rel="noopener"&gt;FCOPY&lt;/A&gt; function.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Good idea for normal files, but probably not the right way to copy SPDE datasets.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 13:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762050#M39337</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-17T13:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762105#M39338</link>
      <description>&lt;P&gt;You will find my code below.&amp;nbsp; However, I would like to check if the dataset exist before making the proc datasets but&amp;nbsp;&lt;/P&gt;
&lt;P&gt;my if statement does not seems to work.&amp;nbsp; Is there a way to correct that or an options with the proc datasets to avoid trying to copy a dataset that does not exist.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please note that the call execute with the proc datasets seems to work properly except due to the if statement that is not&lt;/P&gt;
&lt;P&gt;working properly, it may try to copy a dataset that does not exist giving error into the log file&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/******* Check if a dataset exist using a macro function % and the macrovariable exist (1 for yes, 0 for no)*/&lt;BR /&gt;/* Example of call for the macro function %checkds : %checkds(sashelp.class); %put &amp;amp;=exist; *************/&lt;BR /&gt;%macro checkds(dsn);&lt;BR /&gt;%global exist;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn)) %then &lt;BR /&gt;%do;&lt;BR /&gt;%let exist=1;&lt;BR /&gt;run;&lt;BR /&gt;%end;&lt;BR /&gt;%else &lt;BR /&gt;%do;&lt;BR /&gt;%let exist=0;&lt;BR /&gt;%end;&lt;BR /&gt;%mend checkds;&lt;/P&gt;
&lt;P&gt;/***********************************************************/&lt;BR /&gt;%let path1=/source;&lt;BR /&gt;%let path2=/destination;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;length folderpath1 folderpath2 $60 fname $20 L 3.;&lt;BR /&gt;array ld {9} $8 ('20210729' '20210730' '20210731' '20210801' '20210802' '20210803' '20210804' '20210805' '20210806');&lt;BR /&gt;array lcp {5} $2 ('A' 'B' 'C' 'D' 'E');&lt;BR /&gt;array bc {2} $4 ('auto' 'habi');&lt;BR /&gt;do i=1 to 1 /*dim(lcp)*/;*do i=1 to 5;&lt;BR /&gt;if lcp(i) in ('A','B') then L=1;&lt;BR /&gt;else L=2;&lt;BR /&gt;put L;&lt;BR /&gt;do j=1 to L;*do j=1 to L (1 or 2);&lt;BR /&gt;folderpath1=catx('/',"&amp;amp;path1.",lcp(i),bc(j));&lt;BR /&gt;folderpath2=catx('/',"&amp;amp;path2.",lcp(i),bc(j));&lt;/P&gt;
&lt;P&gt;/******* assign two libraries ****/&lt;BR /&gt;call execute(cat('libname src1 spde'," ","'",folderpath1,"';"));&lt;BR /&gt;call execute(cat('libname dest1 spde'," ","'",folderpath2,"';"));&lt;BR /&gt;&lt;BR /&gt;/********* copying the dataset for src1 to dest1 ************************/&lt;/P&gt;
&lt;P&gt;do k=1 to dim(ld);&lt;BR /&gt;&lt;BR /&gt;fname=cat(lcp(i),bc(j),'_prm_d',ld(k));&lt;BR /&gt;/* checking if the dataset exist */&lt;BR /&gt;call execute(cats('%checkds(src1.',fname,');'));&lt;BR /&gt;if "&amp;amp;exist." eq 1 then &lt;BR /&gt;do;&lt;BR /&gt;put fname;&lt;BR /&gt;call execute(cat('proc datasets lib=src1;','copy out=dest1 memtype=(data);','select ',cats(fname),';run;')); &lt;BR /&gt;end; &lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 15:48:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762105#M39338</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-17T15:48:38Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762113#M39339</link>
      <description>Change your IF to a macro conditional %IF instead.</description>
      <pubDate>Tue, 17 Aug 2021 16:06:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762113#M39339</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-17T16:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762143#M39340</link>
      <description>&lt;P&gt;I have tried the %if and it did not work better.&lt;/P&gt;
&lt;P&gt;it seems that the macro variable that the first value of the loop and that it is not updated for some reasons, I don't understand&lt;/P&gt;
&lt;P&gt;Does someone has an idea why and or to solve that issue?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 18:38:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762143#M39340</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-17T18:38:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762148#M39341</link>
      <description>You didn't provide the code for %checkds or your version with %IF ....</description>
      <pubDate>Tue, 17 Aug 2021 18:51:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762148#M39341</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-17T18:51:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762152#M39342</link>
      <description>&lt;P&gt;/******* Check if a dataset exist using a macro function % and the macrovariable exist (1 for yes, 0 for no)*/&lt;BR /&gt;/* Example of call for the macro function %checkds : %checkds(sashelp.class); %put &amp;amp;=exist; *************/&lt;/P&gt;
&lt;P&gt;%macro checkds(dsn);&lt;BR /&gt;%global exit;&lt;BR /&gt;%if %sysfunc(exist(&amp;amp;dsn)) %then %do;&lt;BR /&gt;data _null_;&lt;BR /&gt;call symputx('exist',1);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;%end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/***********************************************************/&lt;BR /&gt;%let path1=/source1;&lt;BR /&gt;%let path2=/dest1;&lt;/P&gt;
&lt;P&gt;data _null_;&lt;BR /&gt;length folderpath1 folderpath2 $60 fname $20 L 3.;&lt;BR /&gt;array ld {9} $8 ('20210729' '20210730' '20210731' '20210801' '20210802' '20210803' '20210804' '20210805' '20210806');&lt;BR /&gt;array lcp {5} $2 ('A' 'B' 'C' 'D' 'E');&lt;BR /&gt;array bc {2} $4 ('auto' 'habi');&lt;BR /&gt;do i=1 to 1 /*dim(lcp)*/;*do i=1 to 5;&lt;BR /&gt;if lcp(i) in ('A','B') then L=1;&lt;BR /&gt;else L=2;&lt;BR /&gt;put L;&lt;BR /&gt;do j=1 to L;*do j=1 to L (1 or 2);&lt;BR /&gt;folderpath1=catx('/',"&amp;amp;path1.",lcp(i),bc(j));&lt;BR /&gt;folderpath2=catx('/',"&amp;amp;path2.",lcp(i),bc(j));&lt;/P&gt;
&lt;P&gt;/******* assign two libraries ****/&lt;BR /&gt;call execute(cat('libname src1 spde'," ","'",folderpath1,"';"));&lt;BR /&gt;call execute(cat('libname dest1 spde'," ","'",folderpath2,"';"));&lt;BR /&gt;&lt;BR /&gt;/********* copying the dataset for src1 to dest1 ************************/&lt;/P&gt;
&lt;P&gt;do k=1 to dim(ld);&lt;BR /&gt;&lt;BR /&gt;fname=cat(lcp(i),bc(j),'_prm_d',ld(k));&lt;BR /&gt;/* checking if the dataset exist */&lt;BR /&gt;call execute(cats('%checkds(src1.',fname,');'));&lt;BR /&gt;/* it seems that after the above call execute, the macro &amp;amp;exist. is not updated*/&lt;BR /&gt;put "the value of the flag is &amp;amp;exist.";&lt;BR /&gt;%if "&amp;amp;exist." eq 1 %then &lt;BR /&gt;%do;&lt;BR /&gt;put fname; &lt;BR /&gt;%end; &lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 19:29:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762152#M39342</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-17T19:29:24Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762158#M39343</link>
      <description>Could you please comment your code and then I'll add the corrections/ updates. I noticed that your %IF doesn't actually include your CALL EXECUTE anymore.....</description>
      <pubDate>Tue, 17 Aug 2021 20:11:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762158#M39343</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-17T20:11:56Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762164#M39344</link>
      <description>&lt;P&gt;I have retreive the call execute to simplify.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The idea is to check if the dataset exist.&amp;nbsp; If so, the put the name of the dataset into the logfile.&lt;/P&gt;
&lt;P&gt;among the list of data set, for Company A, business line auto, I have the following possibilities.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Aauto_prm_d20200729&lt;/P&gt;
&lt;P&gt;Aauto_prm_d20200730&lt;/P&gt;
&lt;P&gt;Aauto_prm_d20200731&lt;/P&gt;
&lt;P&gt;Aauto_prm_d20200801&lt;/P&gt;
&lt;P&gt;Aauto_prm_d20200802&lt;/P&gt;
&lt;P&gt;Aauto_prm_d20200803&lt;/P&gt;
&lt;P&gt;Aauto_prm_d20200804&lt;/P&gt;
&lt;P&gt;Aauto_prm_d20200805&lt;/P&gt;
&lt;P&gt;Aauto_prm_d20200806&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So it is all the possible dataset name into that folder, except the the&amp;nbsp;Aauto_prm_d20200802 does not exist.&lt;/P&gt;
&lt;P&gt;Therefore, what's I am trying to do is to use the call execute (%checkds(src1.fname)) to obtain the value of exist.&lt;/P&gt;
&lt;P&gt;If the file exits then exits=1 otherwise exist=0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I that portion of the code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;do k=1 to dim(ld);&lt;/P&gt;
&lt;P&gt;fname=cat(lcp(i),bc(j),'_prm_d',ld(k));&lt;BR /&gt;call execute(cats('%checkds(src1.',fname,');'));&lt;BR /&gt;if "&amp;amp;exist." eq 1 then &lt;BR /&gt;do;&lt;BR /&gt;put fname;&lt;BR /&gt;end;&lt;BR /&gt;end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to check if the dataset fname exist if so, put the fname into the logfile if not I don't want to see it.&lt;/P&gt;
&lt;P&gt;When this codition will be respected, I will replace the put fname statement by:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;call execute(cat('proc datasets lib=src1;','copy out=dest1 memtype=(data);','select ',cats(fname),';quit;'));&lt;/P&gt;
&lt;P&gt;in order to copy fname from src1 to dest1&lt;/P&gt;
&lt;P&gt;Again, if the file does not exit, I don't want this call execute to be perform, to avoid to get an error, as the file does not exits.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Up to now, it seem that when it enter into the loop , it take the first value of exist and keep it.&lt;/P&gt;
&lt;P&gt;It is like in the loop, this call execute(cats('%checkds(src1.',fname,');')); is supposed to be executed but the macro variable exist is not updated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't know what to do.&lt;/P&gt;
&lt;P&gt;I hope you will be able to help&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 20:26:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762164#M39344</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-17T20:26:42Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762166#M39345</link>
      <description>&lt;P&gt;SYMBOLGEN: Macro variable DSN resolves to src1.Aauto_prm_d20210801&lt;BR /&gt;MLOGIC(CHECKDS): %IF condition %sysfunc(exist(&amp;amp;dsn)) is TRUE&lt;BR /&gt;MPRINT(CHECKDS): Data _null_;&lt;BR /&gt;MPRINT(CHECKDS): call symputx('exist',1);&lt;BR /&gt;MPRINT(CHECKDS): run;&lt;BR /&gt;MLOGIC(CHECKDS): %PUT "&amp;amp;=exist."&lt;BR /&gt;SYMBOLGEN: Macro variable EXIST resolves to 1&lt;BR /&gt;"EXIST=1"&lt;BR /&gt;MLOGIC(CHECKDS): Ending execution.&lt;BR /&gt;Aauto_prm_d20210801&lt;BR /&gt;MLOGIC(CHECKDS): Beginning execution.&lt;BR /&gt;MLOGIC(CHECKDS): Parameter DSN has value src1.Aauto_prm_d20210802&lt;BR /&gt;MLOGIC(CHECKDS): %GLOBAL EXITS&lt;BR /&gt;SYMBOLGEN: Macro variable DSN resolves to src1.Aauto_prm_d20210802&lt;BR /&gt;MLOGIC(CHECKDS): %IF condition %sysfunc(exist(&amp;amp;dsn)) is FALSE&lt;BR /&gt;MPRINT(CHECKDS): Data _null_;&lt;BR /&gt;MPRINT(CHECKDS): call symputx('exist',0);&lt;BR /&gt;MPRINT(CHECKDS): run;&lt;BR /&gt;MLOGIC(CHECKDS): %PUT "&amp;amp;=exist."&lt;BR /&gt;SYMBOLGEN: Macro variable EXIST resolves to 1&lt;BR /&gt;"EXIST=1"&lt;BR /&gt;MLOGIC(CHECKDS): Ending execution.&lt;BR /&gt;Aauto_prm_d20210802&lt;/P&gt;</description>
      <pubDate>Tue, 17 Aug 2021 21:00:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762166#M39345</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-17T21:00:39Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762172#M39346</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;do k=1 to dim(ld);

fname=cat(lcp(i),bc(j),'_prm_d',ld(k));
call execute(cats('%checkds(src1.',fname,');')); /* this pushes the macro onto the execution stack while the data step is running */
if "&amp;amp;exist." eq 1 then /* but this is evaluated when the data step is compiled, _before_ it executes */
do;
put fname;
end;
end;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Aug 2021 21:30:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762172#M39346</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-08-17T21:30:53Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762196#M39347</link>
      <description>&lt;P&gt;You don't seem to understand how CALL EXECUTE() works and when the generated code works.&amp;nbsp; That is another reason to use the write a file method.&amp;nbsp; You are much less likely to get confused about when the generated code will run.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would probably be easier to create a macro that confirms the list of files before trying to copy them.&lt;/P&gt;
&lt;P&gt;Something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro copy_members(inlib,outlib,memlist);
proc sql noprint;
select nliteral(memname) into :memlist separated by ' '
from dictionary.members
where libname="%upcase(&amp;amp;inlib)"
  and memtype='DATA'
  and findw("&amp;amp;memlist",memname,' ','sit')
;
quit;
%if &amp;amp;sqlobs %then %do; 
proc copy inlib=&amp;amp;inlib outlib=&amp;amp;outlib memtype=data;
   select &amp;amp;memlist ;
run;
%end;

%mend copy_members;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Example usage:&lt;/P&gt;
&lt;PRE&gt;332   options mprint;
333   %copy_members(inlib=sashelp,outlib=work,memlist=cars class xyz);
MPRINT(COPY_MEMBERS):   proc sql noprint;
MPRINT(COPY_MEMBERS):   select nliteral(memname) into :memlist separated by ' ' from dictionary.members where libname="SASHELP" and
memtype='DATA' and findw("cars class xyz",memname,' ','sit') ;
MPRINT(COPY_MEMBERS):   quit;
NOTE: PROCEDURE SQL used (Total process time):
      real time           0.03 seconds
      cpu time            0.04 seconds


MPRINT(COPY_MEMBERS):   proc copy inlib=sashelp outlib=work memtype=data;
MPRINT(COPY_MEMBERS):   select CARS CLASS ;
MPRINT(COPY_MEMBERS):   run;

NOTE: Copying SASHELP.CARS to WORK.CARS (memtype=DATA).
NOTE: There were 428 observations read from the data set SASHELP.CARS.
NOTE: The data set WORK.CARS has 428 observations and 15 variables.
NOTE: Copying SASHELP.CLASS to WORK.CLASS (memtype=DATA).
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.CLASS has 19 observations and 5 variables.
NOTE: PROCEDURE COPY used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds
&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Aug 2021 23:12:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762196#M39347</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-17T23:12:04Z</dc:date>
    </item>
    <item>
      <title>Re: how to use array to pass information , assign two libraries and copy some datasets from src1 to</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762283#M39348</link>
      <description>Thanks a lot Kurt for your completary information. Is there a way to check if a dataset exist in a do loop before making a proc datasets?  Or course to make a list of available datasets is an option, I complety forgot to look at.  But, the interest to be able to check if a dataset exist remain something, I would like to look at.&lt;BR /&gt;&lt;BR /&gt;Best Regards&lt;BR /&gt;</description>
      <pubDate>Wed, 18 Aug 2021 13:53:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/how-to-use-array-to-pass-information-assign-two-libraries-and/m-p/762283#M39348</guid>
      <dc:creator>alepage</dc:creator>
      <dc:date>2021-08-18T13:53:56Z</dc:date>
    </item>
  </channel>
</rss>

