BookmarkSubscribeRSS Feed
JustSomeGuy
Calcite | Level 5

I have some SAS code that writes out to an excel workbook located on a windows server. SAS is running on a linux server.

Is it possible to have SAS copy and paste that workbook with a different name on the windows server? Basically the workbook is a template that gets populated and I want to be able to run the code multiple times and end up with multiple populated templates. The way it's structured now after each run I have to copy out the populated template and put another blank one in the location.

9 REPLIES 9
JustSomeGuy
Calcite | Level 5

So I could just set my two filenames using PCFILES and then run this macro? Will there be any issues because these are macro enabled workbooks with macros and lots of formulas, not just simple excel worksheets?

OS2Rules
Obsidian | Level 7

I think your best bet is to have SAS submit a DOS command to copy / rename the file before you populate data.  I don't think there should be any difficulty accessing the file as long ans the directories are available to the system running the command.

JustSomeGuy
Calcite | Level 5

The only way I've seen to have SAS submit DOS commands is with x. How do I use x while also telling it to run the command on a different server than where SAS is installed?

data_null__
Jade | Level 19

I like unnamed pipe for executing OS commands.  You have good control of the output and you can use FILEVAR= option to execute a number of different commands in the same data step.

JustSomeGuy
Calcite | Level 5

So you're recommending that I use unnamed pipe to copy and rename the file with windows command line? Are there any limitations to this being that I need to use the pipe on a different server than where SAS is running? I've started googling but had never heard of this before so more detail would be helpful.

data_null__
Jade | Level 19

You said you only knew of X command to execute DOS commands.  I was suggesting PIPE because you have greater control over the output from each command this is executed.

http://support.sas.com/documentation/cdl/en/hostwin/63047/HTML/default/viewer.htm#n16puwsro9pakqn1ja...

You don't have to use the FILENAME statement you can also use pipes with the FILEVAR option which allows a single data step to "do it all".

What is the command that you need to execute?

JustSomeGuy
Calcite | Level 5

The command I want to execute would copy a file (leaving it in the same directory) and then rename it. So with the pipe method I can use a filename statement (which I can define as on a different server, correct?) and have the command in there? Am I understanding this right? Thanks for your help!

I'm really not sure how to go about getting the result I desire. My SAS code already writes out to the workbook correctly, but I want to add something so after it writes out that work book gets copied and has a different name.

data_null__
Jade | Level 19

I don't understand your parentheticals.

I don't know if this example will be helpful or not but it is the kind of thing I am talking about.  It is submitted from EG on a unix server.

16         data _null_;
17            length command $128 source target $64;
18            source = '~/shoes.xlsx';
19            target = '~/newshoes.xlsx';
20            command = catx(' ','/usr/bin/cp',source,target);
21            link runit;
22            command = catx(' ','/usr/bin/ls -l', target);
23            link runit;
24            stop;
25          runit:
26            infile dummy pipe filevar=command end=eof;
27            do while(not eof);
28               input;
29               put 'NOTE: ' _infile_;
30               end;
31            return;
32            run;

NOTE:
The infile DUMMY is:
      Pipe command=
"/usr/bin/cp ~/shoes.xlsx ~/newshoes.xlsx"

NOTE: The infile DUMMY is:
      Pipe command=
"/usr/bin/ls -l ~/newshoes.xlsx"

NOTE: -rw-rw-r--  
1 .......  users      19200 Jan 24 04:50 /home/......./newshoes.xlsx
NOTE:
0 records were read from the infile DUMMY.
NOTE:
1 record was read from the infile DUMMY.
      The minimum record length was
81.
      The maximum record length was
81.
NOTE: DATA statement used (Total process time):
      real time          
0.16 seconds
      cpu time           
0.00 seconds

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 2088 views
  • 0 likes
  • 4 in conversation