There and back again: copying files in SAS Enterprise Guide

One of the problems that trips up experienced SAS users when they begin to use SAS Enterprise Guide is a result of simple geography.

The SAS Enterprise Guide application runs here, on your desktop. The SAS Workspace session (which accesses data and cranks through your analysis) runs over there, on a remote machine. If you're accustomed to "PC SAS" running all on your local box, you might be forced to rethink a few of your processes. For example, do you have Excel files on your PC to import using PROC IMPORT? Does your SAS program create output that you have to save on your PC? How will you get these files to where they need to be?

There are some strategies that help, including mapped drives, UNC paths, and network shares via a mechanism like Samba. These mechanisms allow your local SAS Enterprise Guide and your remote SAS to "see" a shared location on the network. Also, SAS Enterprise Guide has a few focused tasks that can "move" files for you under the guise of "import" and "export" steps.

But there isn't a general method to copy any file you want from your PC to the SAS Workspace, or from the SAS Workspace to your PC. Until now.

I give you: the Copy Files task for SAS Enterprise Guide.

What "Copy Files" does

The Copy Files task allows you to capture file transfer steps within your SAS Enterprise Guide process flow. You can upload files from your local PC to the remote machine where your SAS Workspace is running. And you can download files from your remote SAS Workspace to a folder on your local PC. It is similar in concept to an FTP process, except that this transfer operation uses your already-existing connection to a SAS Workspace and does not require a separate application.

Some readers might be familiar with SAS/CONNECT Data Transfer Services (PROC UPLOAD and PROC DOWNLOAD), which allows you to transfer files between two SAS sessions. Again, this is similar in concept, but since there is only one SAS session in play here, we need to use a different mechanism.

How to copy files in bulk

The Copy Files task supports two features that allow you to copy multiple files with a single step. First, you can use wildcard characters to match on multiple file names. An asterisk (*) matches all characters, in any number, before the next non-wildcard character. A question mark (?) matches any single character that occupies that position in the file name.

Second, you can use SAS macro variables and expressions to specify any part of the source file names or destination folder. Use a SAS program to determine the files you need to copy earlier in the process, assign that value to a macro variable, and then have the task "dynamically" select the correct files when it's time to copy them.

Support for Task Templates

The Copy Files task also supports a standard SAS Enterprise Guide feature: Task Templates. You can create an instance of the task that is useful in one process, then save those task settings to your personalized set of Task Templates that you can use in another process or even in another project. To save your settings as a template, right-click on the Copy Files task within your process flow and select Create Task Template. To use the new template, select it as a menu item from Tasks->Task Templates.

Limitations to note

This task does not generate a SAS program that you can reuse in a batch SAS process or SAS stored process. The task works by using SAS Workspace APIs to transfer data across your network connection, so all of the work happens "behind the scenes". However, the task does create a detailed log output that shows what files were copied, how many bytes were transferred, how long it took, and whether there were any errors.

How to get the task

You can download the Copy Files task from this link (Zip file). The download package includes three versions that depend on your version of SAS Enterprise Guide: one for v4.3, one for v5.1, and one for v4.1 (with a reduced feature set). There is also a documentation file (PDF) that provides instruction for how to install and use the task.

Update 15Aug2014: SAS users often ask me for an updated version to work with SAS Enterprise Guide 6.1. The 5.1 version of the task has always worked fine with the 6.1 version of the application. But the instructions were not clear on that, so I've built a "6.1" version of the task and added it to the package. If the 5.1 version has been working for you, there is no need to change. If you want to try the 6.1 version (which will work only with SAS Enterprise Guide 6.1), then you now have the option.

tags: Copy Files, FTP, PROC DOWNLOAD, PROC UPLOAD, SAS custom tasks, SAS Enterprise Guide

65 Comments

  1. Bruno
    Posted December 7, 2012 at 3:07 am | Permalink

    Early Christmas, thank you for this great tool Chris

  2. Bob Duell
    Posted December 22, 2012 at 11:48 am | Permalink

    Very nice! I'd love to see this enhanced with point-and-click dialog boxes to select the files (rather than manually typing them into the field), if not for the "remote server" side then at least for the "local" PC side.

    This is a great enhancement, solving a big "usability" problem. Thanks!

  3. Jacob Keng
    Posted December 25, 2012 at 8:54 am | Permalink

    "and one for v4.1 (with a reduced feature set).",what does it mean?Can the version for v4.1 copy multiple files?
    Thanks Chris!

    • Chris Hemedinger Chris Hemedinger
      Posted December 28, 2012 at 12:39 pm | Permalink

      Yes, it can - it supports wildcard notation. But the user interface is a bit more rudimentary, and it doesn't support Task Templates (available in EG 4.2 and later).

  4. Jacob Keng
    Posted January 2, 2013 at 11:38 am | Permalink

    For "Upload from local PC to SAS session", it's OK.But it does not support wildcard notation when download from SAS session to local PC. Is it ok with yours? Or it is just a reduced feature set.

    • Chris Hemedinger Chris Hemedinger
      Posted January 2, 2013 at 11:50 am | Permalink

      Jacob,

      Are you referring to the 4.1 version? It *should* support wildcard notation for source files, whether coming from your local PC or the remote SAS file system. If you're not seeing that, please post back with the content of the log output and I'll try to see what's going on.

      • Jacob Keng
        Posted January 7, 2013 at 11:16 am | Permalink

        Chris,
        Yes,I am referring to the 4.1 version.

        Source files:    /sascnapp/data/dm/psacn147/test/*.sas7bdat
        Destination folder:     I:\Jacob_I
        ERROR: File /sascnapp/data/dm/psacn147/test/*.sas7bdat not a valid file
        

        There existed txt,csv,sas7bdat files under test folder.
        I tryed "*.txt" and "*.csv",none successed.My colleagues meet the same issues.
        I think it might be the problem of the server where SAS EG4.1.0.0 installed,but not sure.
        Do you have any suggestions?
        By the way,I'm from Shanghai,and my English is not good,and expression may be not clear or syntax error.If you think my expression is not clear,please let me know.
        Thanks very much.

        • Chris Hemedinger Chris Hemedinger
          Posted January 7, 2013 at 11:28 am | Permalink

          Jacob,

          I understand the problem...but I cannot tell from the error what the cause is. It's possible that the path you are specifying is different from the SAS file system. That is, the path might need to be expressed differently.

          To test, can you run a SAS program from EG with this statement?

          libname test "/sascnapp/data/dm/psacn147/test/";
          proc datasets lib=test;
          quit;
          

          If that works, then SAS sees the path as valid and accessible. If not, then it's possible you need to supply a more complete path in order for SAS to resolve it.

          • Jacob Keng
            Posted January 7, 2013 at 12:00 pm | Permalink

            Chris,
            The path is OK,I use ' libname test "/sascnapp/data/dm/psacn147/test/"; '
            or ' libname Temp "/sascnapp/data/dm/psacn147/MIS361/201212";'
            or ' libname test "/sascnapp/data/dm/psacn147/&StaMth."; '(such as %let &StaMth=201301),
            ect.,everyday,and SET datasets into the lib.It does work.
            Is it that it did not resolve numbers??Oh,I'll test it tomorrow.
            Thanks.

          • Chris Hemedinger Chris Hemedinger
            Posted January 7, 2013 at 12:06 pm | Permalink

            Okay, remember these limitations:
            - the wildcard notation is only on the file name, not the folder names. The task won't resolve wildcards in folder names.
            - the Copy Files task doesn't search into subfolders and process the directories "recursively". It operates only on the one named folder path.

          • Jacob Keng
            Posted January 9, 2013 at 7:54 pm | Permalink

            Chris,
            This is not the problem of path.It may be the server.Anyway,I find another way to DOWNLOAD files.
            Thanks very much for your advice.

          • Jacob Keng
            Posted January 18, 2013 at 11:36 am | Permalink

            Chris,
            Make a little change,

            /sascnapp/data/dm/psacn147/test/MIS*.sas7bdat

            then it works! How Strange!

          • Chris Hemedinger Chris Hemedinger
            Posted January 18, 2013 at 11:38 am | Permalink

            Excellent! Glad to hear that it's working for you.

  5. Eren
    Posted January 4, 2013 at 12:18 am | Permalink

    This is an elegant tool!
    Thank You Chris.

  6. Roberto Lopez
    Posted January 23, 2013 at 5:47 pm | Permalink

    Chris:
    I'm having the same trouble as a few folks here but lack their .net expertise. To sum up :
    (1) I get the following error when trying to load custom tasks : "Unable to load file...Error: Could not load file or assembly 'SAS.Tasks.ProjectReviewer' or one of its dependencies. Operation is not supported.
    (2) Upon further investigation I believe the issue is addressed in this post by Microsoft :
    http://blogs.msdn.com/b/shawnfa/archive/2009/06/08/more-implicit-uses-of-cas-policy-loadfromremotesources.aspx
    (3) Essentially I need to bypass the issue is by setting :

    loadFromRemoteSources enabled="true"

    The problem is I don't know where to do that. I tried modifying the SAS config file for the executable but then SAS would not load. It could be that I set it in the wrong place.

    Do you think you can provide some insight?

  7. Tony
    Posted January 23, 2013 at 8:48 pm | Permalink

    This is EXCELLENT! We just switched to SAS on a server from PC. This was a major problem until I stumbled upon The Dummy Blog and found this handy add-in. Thanks for sharing it.

  8. Tom
    Posted February 12, 2013 at 2:58 pm | Permalink

    Chris,

    Thanks for this! I found it yesterday and am using it in conjunction with a web service. Fantastic!

    • Chris Hemedinger Chris Hemedinger
      Posted February 12, 2013 at 3:09 pm | Permalink

      Tom, great to hear it! "Copy files task" + "web service" isn't a mashup that I imagined, but I find that SAS users are often more creative than I am at solving problems.

  9. Tom
    Posted February 22, 2013 at 1:38 pm | Permalink

    Hi Chris,

    We installed the DLL in the specific users directory originally (C:\Documents and Settings\\Application Data\SAS\EnterpriseGuide\5.1), then changed our minds. When we removed it from the users directory and placed it in the app directory (C:\Program Files\SASHome\SASEnterpriseGuide\5.1\Custom), the DLL doesn't function. Is there a registry change that has to be made or is there a setting within EG itself that can be altered to override the original location of the DLL?

    Overall, fabulous task!

    -Tom

  10. Posted March 18, 2013 at 4:32 pm | Permalink

    Hi Chris,
    I have problems installing this add-on on my EG 4.3. It says that ''Unable to load file SASFileTransferTasks43.dll. Error: Add-In is invalid file type."
    The dll-file is located the same place as two of your other very nice add-ins, which works perfectly fine. It doesn't make any difference that i unblock the files. Hope you have some suggestions because I really need the Add-In feature :-)

    • Chris Hemedinger Chris Hemedinger
      Posted March 19, 2013 at 8:40 am | Permalink

      Rune, the file name *should* be SAS.Tasks.CopyFiles43.dll. Maybe you transcribed the message incorrectly in the comment, but just want to make sure.

      You can capture a few more diagnostics by turning on logging using the instructions in this SAS Note. If you do that, you'll find a text file with internal logging activity in the %appdata%\sas\enterpriseguide\4.3\logs folder. If you capture the log while you see the "add-in" error message, there should be some additional entries in the log around SAS.Tasks.CopyFiles43.dll and the SasFileTransferTask. If you post those back (or e-mail to chris.hemedinger [at] sas.com) I'll take a look.

      • Rune
        Posted March 21, 2013 at 8:45 am | Permalink

        Hi Chris,

        You are ofcause right that I transcripted the message incorrectly, the file name is "SAS.Tasks.CopyFiles43.dll".

        I tried turning on logging and got the following result:

        [Main] INFO SAS.Shared.AddIns.Management.AddInRegistry [(null)] - Loading custom task assembly: \\De2900\STRAT\Diverse\SAS\EG\SAS.MacroViewer\SAS.MacroViewer.dll
        [Main] INFO SAS.Shared.AddIns.Management.AddInRegistry [(null)] - Successfully loaded custom task assembly: SAS.MacroViewer, Version=4.3.0.0, Culture=neutral, PublicKeyToken=null
        [Main] WARN SAS.Shared.AddIns.Management.AddInRegistry [(null)] - Type OptionsTask failed inspection as a custom task: Exception has been thrown by the target of an invocation.
        [Main] WARN SAS.Shared.AddIns.Management.AddInRegistry [(null)] - Type MacroTask failed inspection as a custom task: Exception has been thrown by the target of an invocation.
        [Main] ERROR SAS.Shared.AddIns.Management.ManagerForm [(null)] - GetAddInRegistryInfo() -
        System.Exception: Add-In is an invalid file type.
        at SAS.Shared.AddIns.Management.AddInRegistry.LoadElementFromAssembly(String targetAssembly)
        at SAS.Shared.AddIns.Management.ManagerForm.GetAddInRegistryInfo(String FilePath)

        Any suggestions? I have the same problem with the Macro variable viewer, but not with the SAS Catalog Explorer.

        • Chris Hemedinger Chris Hemedinger
          Posted March 21, 2013 at 9:01 am | Permalink

          Rune, it looks like you are trying the load the DLL from a UNC path (\\de2900). By default, The .NET Framework disables loading assemblies (DLLs) from network paths, through a feature called "Code Access Security". You'll need to put the DLL on a local drive (not network drive) in order for EG to pick it up. Alternatively, you can enable the Code Access Security by adding your network location as a Full Trust location. To do this, you launch ".NET Framework 2.0 Configuration" (tool on your Windows machine), then select Configure Code Access Security, then either Increase Assembly Trust (to add just the one assembly) or Adjust Zone Security (to make your Local Intranet have Full Trust). Search for "Microsoft .NET code access security" for more background and instructions for the tool.

  11. Prashant
    Posted April 17, 2013 at 9:24 am | Permalink

    Hi Chris,
    We are using SAS 9.2 with EG 4.2 version do you also have a copy utility for that.4.1 and 4.3 is not working.

    Also We are planning to migrate on EG5.1 Citirx but in PoC I could not locate SAS EG on my local machine.Could you please help?

    • Chris Hemedinger Chris Hemedinger
      Posted April 17, 2013 at 9:27 am | Permalink

      Prashant,

      Sorry, I don't have a 4.2 version of the Copy Files utility at this time. If you're planning to move to 5.1 anyway, it sounds like your need for a 4.2 version is short-lived (I hope).

      Regarding migrating to Citrix: if you run via Citrix or Terminal Server, your EG session is on a remote Windows environment that you log into. It won't be on your local machine. Thus, a tool like Copy Files (if that's what you're trying to use) has to be installed on the Citrix environment as well. You'll need to ask your IT support staff to help make that happen.

  12. Jeremy J Griffith
    Posted May 17, 2013 at 12:08 am | Permalink

    Thank you! This is great! I look forward to integrating all of those repetitive file transfers right into my Process Flow!

  13. Amey A Kokane
    Posted May 21, 2013 at 4:15 pm | Permalink

    Hi Chris,
    First of all thank you for this lovely little peice of work.
    I am getting following error when I try to copy files using this copy task:
    "ERROR: Unable to locate files within the path /saspext1/z2/sasdata/kokanea/*.xls."
    I did check if SAS path is a valid path. If you or anyone can shed some light on what is this error, it would be great.
    Thanks in advance!

    • Chris Hemedinger Chris Hemedinger
      Posted May 21, 2013 at 4:20 pm | Permalink

      Amey,

      Do you have the most recent version of the task? This type of path would work only after getting the version I posted last week. Any easy way to tell if you have the latest: the updated version also has a Save button on the bottom, whereas the earlier version did not (had only a Run button, plus Cancel and Help).

      • Amey Kokane
        Posted May 23, 2013 at 10:47 am | Permalink

        Thanks for the prompt reply Chris.
        I used the new version after I saw your comment but still no success. May its because SAS EG is connected a data library onto a unix server.
        I am also having problems running the EG Scheduler and sas support said it will give you a problem if you are working in client-server environment.
        If you can direct me to some material that I can refer to for this problems, I would appreciate it.
        Thanks for your help !

        • Chris Hemedinger Chris Hemedinger
          Posted May 23, 2013 at 11:10 am | Permalink

          Amey, another thing to check is that you can actually reach the path you supplied via a SAS program on this workspace. The path you supplied might not be a good reference in terms of the SAS Workspace environment.

          Sample test to run from an EG program node:

          %let folder=/saspext1/z2/sasdata/kokanea;
          /* Check for presence of a KNOWN xls file */
          data _null_;
           if fileexist("&folder./myfile.xls") then
            call symputx('file_found','1');
           else 
            call symputx('file_found','0');
          run;
          %put FILE_Found = &file_found.;
          
  14. Brian
    Posted June 7, 2013 at 3:56 pm | Permalink

    Hi. I was able to use this program sucessfully to move .xls files from a network folder to a Linux server. However, I was not able to move .xlsX files. The log said that the files were moved (it showed the bytes moved) but on the linux box the files showed up as 0 bytes. Is it possible to use this for .xlsX files ? Thanks.

    • Chris Hemedinger Chris Hemedinger
      Posted June 9, 2013 at 2:04 pm | Permalink

      Brian,

      Yes, *.xlsx files should work, and they always have worked fine in my tests -- even when transferring them to Linux. If you continue to have troubles, respond back and I'll help you to diagnose it.

  15. Todd Gerber
    Posted June 11, 2013 at 11:22 am | Permalink

    Hi Chris,

    I'm also having trouble registering the Add-in. I'm running SAS EG v5.1 thin client on a 64 bit workstation and Linux 64 bit server. I'm getting a message that the Add-in Manager is "Unable to load file C:\Program Files\SASHome\SASEnterpriseGuide\5.1\Custom\SAS.Tasks.CopyFiles51.dll. Error: Could not load file or assembly 'SAS.Tasks.CopyFiles51' or one of its dependencies. Operation is not supported. (Exception from HRESULT: 0x80131515)"
    I read the previous posts and "Unblocked" the file using Windows Explorer. What am I doing wrong? Thanks! -Todd

    • Chris Hemedinger Chris Hemedinger
      Posted June 11, 2013 at 11:30 am | Permalink

      Todd,

      It might be that you don't have the "unblock" permissions necessary -- your error message is definitely consistent with the "blocked DLL" situation. See my update in this post for "special steps".

      • Todd Gerber
        Posted June 18, 2013 at 11:31 am | Permalink

        Hi Chris,

        Thanks for your help. Our Help desk managed to unblock the file for me - I didn't have the necessary permissions. I uploaded a test *.txt file and now have problems with my infile statement "ERROR: Physical file does not exist, /home/tgerber/HCC/ff_IFE_MBR_ELIG_EXT.txt." I'm googling this error now. Does anyone know if it is possible to read txt files without going through the IMPORT utility on SAS Enterprise Guide? I need to read multiple files that have header and footer records, and I don't see options for this in the GUI. -Todd

        • Chris Hemedinger Chris Hemedinger
          Posted June 18, 2013 at 12:04 pm | Permalink

          Todd, since your file name has mixed-case naming, make sure that the file exists on your UNIX path with that name exactly. UNIX is case-sensitive about file names. You're correct that if you want a process that reads multiple files as a collection, you will need to use a SAS program (and not the Import Data task that EG provides -- although that might help you get started).

  16. Brendan Heavey
    Posted June 26, 2013 at 4:15 pm | Permalink

    Hi Chris-
    This is excellent...I was trolling around looking for info on how to build custom tasks and stumbled into this task which we've been trying to build work arounds for for a few months. I appreciate you posting!

  17. Randy Spell
    Posted July 1, 2013 at 11:47 am | Permalink

    Hi Chris, great utility!
    I was successful getting this to work on my local PC to copy files from a mapped drive to the SAS server (when I use the Mapped drive notation, i.e. u:\*.xlsx). However, our setup for users runs from TSX servers. I have access to log onto the TSX servers and can see my mapped drives from there so would assume this would work. However, I get the following when running the task from a TSX server, and seems that it is done processing...?

    Uploading files from machine "TSX1" to SAS session on "SASApp".

    Using these settings:
    Source file specification: u:\*.xlsx
    Destination path: /svops/sasdata/rtm/oit/oit_share/oit_dev/DATA
    Overwrite existing files: Yes
    Resolve macro references in file paths: No
    Convert line endings for text files: No

    NOTE: Resolving wildcards in u:\*.xlsx to determine files to be uploaded

    • Chris Hemedinger Chris Hemedinger
      Posted July 1, 2013 at 3:38 pm | Permalink

      I'm not familiar with TSX servers but I'm going to guess that this is a way to publish an app "virtually" so that you can use it without installing the app on your local PC. Is that correct? Or is it like a terminal server/Citrix setup? Here are some things to check:
      If you downloaded this task before 16May2013, be sure that you have the most recent version. I posted a new version with some related fixes during May.
      Make sure that EG can see the mapped drive. The mapped drive should show as a location when you select File->Import Data -- you should be able to locate one of your XLSX file on the U:\ path.
      The file search does not recurse through subfolders, so if you have *.xlsx files in the root of U:, your specification should find them. Otherwise you'll have to specify a subfolder path for each specific location.
      If EG can see the U: drive, try "U:\*.xls?" to pick up both XLS and XLSX files.

      • Randy Spell
        Posted July 10, 2013 at 3:55 pm | Permalink

        yes, Terminal Servers. Got it to work, thanks.

  18. Tiho
    Posted July 9, 2013 at 6:43 am | Permalink

    Hi Chris,

    this works great, just have a little problem. When i run the process flow (all queries, program code within process flow) the taks simple doesn't work. The log is following:

    Downloading files from SAS session on "SASApp" to local machine "A22011CA".

    Using these settings:
    Source file specification: D:\Workspace\tihomirz\REPORT\VELIKE IZLOZENOSTI\Velike_izlozenosti_&SYSDATE..xml
    Destination path: C:\Users\tihomirz\Documents\SCHEDULE PROJECTS\VIB\Excel files
    Overwrite existing files: Yes
    Resolve macro references in file paths: Yes
    Convert line endings for text files: No

    NOTE: Resolving macro expressions in file paths. SAS log:

    When i run only this download/upload task, it works.

    Downloading files from SAS session on "SASApp" to local machine "A22011CA".

    Using these settings:
    Source file specification: D:\Workspace\tihomirz\REPORT\VELIKE IZLOZENOSTI\Velike_izlozenosti_&SYSDATE..xml
    Destination path: C:\Users\tihomirz\Documents\SCHEDULE PROJECTS\VIB\Excel files
    Overwrite existing files: Yes
    Resolve macro references in file paths: Yes
    Convert line endings for text files: No

    NOTE: Resolving macro expressions in file paths. SAS log:
    1 The SAS System 12:41 Tuesday, July 9, 2013

    1 ;*';*";*/;quit;run;
    2 OPTIONS PAGENO=MIN;
    3 %let _egcopySource = D:\Workspace\tihomirz\REPORT\VELIKE
    3 ! IZLOZENOSTI\Velike_izlozenosti_&SYSDATE..xml;
    4 %let _egcopyTarget = C:\Users\tihomirz\Documents\SCHEDULE PROJECTS\VIB\Excel files;
    5 %put Source files resolve to &_egcopySource;
    Source files resolve to D:\Workspace\tihomirz\REPORT\VELIKE IZLOZENOSTI\Velike_izlozenosti_09JUL13.xml
    6 %put Target folder resolves to &_egcopyTarget;
    Target folder resolves to C:\Users\tihomirz\Documents\SCHEDULE PROJECTS\VIB\Excel files
    7
    8 QUIT; RUN;
    9

    NOTE: Source file resolved to D:\Workspace\tihomirz\REPORT\VELIKE IZLOZENOSTI\Velike_izlozenosti_09JUL13.xml
    NOTE: Target folder resolved to C:\Users\tihomirz\Documents\SCHEDULE PROJECTS\VIB\Excel files

    Downloading D:\Workspace\tihomirz\REPORT\VELIKE IZLOZENOSTI\Velike_izlozenosti_09JUL13.xml to C:\Users\tihomirz\Documents\SCHEDULE PROJECTS\VIB\Excel files\Velike_izlozenosti_09JUL13.xml ...
    ...Downloaded Velike_izlozenosti_09JUL13.xml, 270,135 bytes

    NOTE: Copied 270,135 bytes in 0.26 seconds.
    NOTE: Total number of files processed: 1

    Please if you could help what should.
    Thx.

    BR,
    Tiho

  19. James Burton
    Posted September 13, 2013 at 10:19 am | Permalink

    Hi. I have managed to get this working on my PC but when running the process flow via a stored process route it doesn't export to my local drive. Is there a workaround for this at all?

    • Chris Hemedinger Chris Hemedinger
      Posted September 13, 2013 at 10:35 am | Permalink

      Unfortunately, this task won't work within a stored process because it uses direct Windows and SAS APIs, not SAS code, to accomplish the file transfer. It's using EG as the mechanism to download the file.

      To work in a stored process, you need the file copy to happen within the SAS code. You can accomplish this by setting the output file location to a place that it accessible from both your server and PC (a shared network drive, for example). Or you can use FILENAME FTP to place the file someplace where you can get to it from other machines.

      If you need this to work from a stored process in the Stored Process Web App, you can create a download package by using some STPSRV_HEADER directives. This SAS Note has an example.

  20. MattH
    Posted October 10, 2013 at 9:39 am | Permalink

    Big Thanks to Chris Hemedinger and the SAS team for this tool. I downloaded it today and it worked great out of the box. Simple installation. The wildcard and macro integration is a great aspect.

    • Chris Hemedinger Chris Hemedinger
      Posted October 10, 2013 at 9:44 am | Permalink

      You're welcome! Thanks for the feedback.

  21. Jason
    Posted October 19, 2013 at 4:31 pm | Permalink

    Chris -

    This add-in has been terrific working with EG and Unix servers. One thing that has been useful about it is using library paths for the Copy Files as well as import/export/ods files. An example is below with %sysfunc(pathname(LIBRARY)).

    proc export data=test
    outfile="%sysfunc(pathname(WORK))/mynewfile.xlsx"
    dbms=xlsx replace;
    run;

    Then in the Copy files add-in, the source file is (with the resolve macro and destination paths checked):
    %sysfunc(pathname(WORK))/mynewfile.xlsx

    Any library can be used but this is a quick way to grab the WORK/RMTWORK/GRIDWORK directory on a unix environment to use for import/export/ftp/ods.

    Thanks,
    Jason

    • Chris Hemedinger Chris Hemedinger
      Posted October 19, 2013 at 6:43 pm | Permalink

      Jason,

      That's a great example of a combination of SAS functions, macros, and the custom task all working for you. Thanks for the sharing your experience!

  22. gary
    Posted February 21, 2014 at 2:05 pm | Permalink

    hello Chris, i have this Copy Files add in up in my tasks. i have use it to linked to my project after a SAS Program, it runs and then goes to the Copy files, but my user def macro vars for my unix folder like this
    /users/work278/&userid./&naout./&Issue_Num._&sysuserid._&sysdate9._nameaddr.xml
    gives me this in the log
    NOTE: Resolving macro expressions in file paths. SAS log:
    1 ;*';*";*/;quit;run;
    2 OPTIONS PAGENO=MIN;
    WARNING: Apparent symbolic reference USERID not resolved.
    WARNING: Apparent symbolic reference NAOUT not resolved.
    WARNING: Apparent symbolic reference ISSUE_NUM not resolved.
    but in the log from the program my macros look fine

    file: /users/work278/nbk1hhk/test/4321_nbk1hhk_21FEB2014_nameaddr.xml
    i have the box checked for the Resolve SAS Macro var.....

    any ideas?
    thanks
    gary

    • Chris Hemedinger Chris Hemedinger
      Posted February 21, 2014 at 2:15 pm | Permalink

      Gary, since some of the macros (like SYSDATE) resolve, it seems that the Copy Files task is working correctly. Is it possible that your SAS Workspace is configured for a SAS Grid Computing environment? That might explain why some macro variables you assigned in one step were not available in another step -- if they were defined using a different grid node.

      You can configure your SAS Enterprise Guide project to NOT use the grid, if permitted by policy at your site.

      • gary
        Posted February 25, 2014 at 11:59 am | Permalink

        Chris, i played with it some more and tried using a %let stmt in my program and assigning that string of macro vars to just one macro var like this

         %let file=/users/work278/&userid./&naout./&Issue_Num._&sysuserid._&sysdate9._nameaddr.xml ;
        

        and then in the Copy from box i just used the &file macro var and it worked fine

        Not sure why it can't resolve all the macros in the box, but building the macro in the program as one string worked
        gary

        • Chris Hemedinger Chris Hemedinger
          Posted February 25, 2014 at 12:13 pm | Permalink

          Gary - thanks for sharing the update. I'm glad it's working for you.

          • gary
            Posted March 14, 2014 at 8:19 am | Permalink

            Chris, also i'm attempting to use the Prompt manager and let the user enter the paths for both as well as some other information. But the macro vars generated in by the Prompts don't resovle for the Copy even though it appears that the Prompt window info is entered before the copy takes place.
            Is there a timing macro issue with Prompts?
            i was able to get it to work if i put a program step before the copy with the prompt manager running for the Data _null_; program.
            thanks
            gary

          • Chris Hemedinger Chris Hemedinger
            Posted March 14, 2014 at 8:34 am | Permalink

            Gary,

            Make sure that when you define your prompt, you check the box "Use prompt value throughout project". See the answer in this communities.sas.com thread.

  23. Dennis Higdon
    Posted April 18, 2014 at 4:25 pm | Permalink

    Chris,
    I've copied the .dll for version 5.1 of EG into the Custom directory.
    However when I try to connect to it in EG I get an error window:
    UNABLE TO LOAD FILE
    C:...|SAS.Tasks.CopyFiles5.1dll
    Error: Could not load file or assembly 'SAS.Tasks.CopyFiles51' or one of its dependencies. Operation is not supported.(Exception from HRESULT:0x80131515).

    What do I need to change to make this work?

    Thanks,
    Dennis

  24. ymliu
    Posted June 22, 2014 at 12:51 am | Permalink

    Dear Sir:
    User your Copy Task. I can copy from local disk to local disk.
    I wish to copy excel file from http. How do I to set Path?
    For example , Http file is "http://xxxx/abc.xls"

    • Chris Hemedinger Chris Hemedinger
      Posted June 22, 2014 at 2:46 pm | Permalink

      You can achieve this with a two-step approach. First, use SAS to retrieve/copy the file from the HTTP location, using PROC HTTP. Then with the file now local to your SAS session, you can use the Copy Files task to copy it from SAS to your desktop local path.

      • Thomas McMahon
        Posted September 23, 2014 at 1:24 pm | Permalink

        Why is there no mention to run this task in code using the SAS PC File service running on the PC and using a access libname statement or Proc Export/Import with a server= (your pc name). It seems this is a way to export a file from Unix/Linux to Windows within programming code. I use EG 5.1 and this worked for me in the past. I am having a problem with the syntax now but believe that I can work that out.

        • Chris Hemedinger Chris Hemedinger
          Posted September 23, 2014 at 1:36 pm | Permalink

          Tom, yes, this is definitely possible. Not everyone has the ability to run the PC File Server on their own PC, of course.

          Also, with the support for DBMS=XLSX, it's now possible to import Excel files on UNIX without needing that PC File Server at all! As long as you can get your XLSX file up to the SAS session...

  25. R2D2
    Posted October 2, 2014 at 5:08 am | Permalink

    Hi Chris,

    thank you so much for the article. How do I use this to copy sources files which are dynamically generated? for eg. I have a sas script that generates an excel file with dynamic name, the dynamic part being todays date. for eg. "abcd_02102014.xlsx". In this case how do I specify the source location? greatly appreciate your advice :)

5 Trackbacks

  1. [...] Copy Files task (for FTP-like file transfers). It supports wildcard notation and macro expressions, providing lots of flexibility. [...]

  2. [...] usefulness, might work against the policies of those who maintain a SAS environment. For example, the Copy Files task makes it very easy to move files between your SAS server and your local PC. Some organizations [...]

  3. [...] Copy Files to/from SAS [...]

  4. [...] few months ago I released the Copy Files task for use with SAS Enterprise Guide. The task allows you to transfer any files between your PC and a [...]

  5. [...] Copy Files to/from SAS Session Need to move files from here to there? If you need to copy files (FTP style) among your PC and the SAS server, this task captures that step. Use wildcards and SAS macro variables to specify which files to move to where. (This is one of the most popular custom tasks.) Download: See this blog post for more information and download link. [...]

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <p> <pre lang="" line="" escaped=""> <q cite=""> <strike> <strong>