I am writing a program to automate a very tedious part of my monthly processes. The first part of that Process is to Unzip a ton of Files, so I've been running many many different test programs to get Unzipping to work. And nothing has Worked, the biggest thing that gets me is, when I run a call system command, it outputs a 0 saying the command worked (I know this is right from other call systems I use in other programs) but nothing Happens, I copy the same code into my CMD and it runs, and it does what it is supposed to, is there anything that could be preventing it from working? here is my Code:(modified for security purposes)
options noxwait;
data testOutput;
command = "PowerShell Expand-Archive -Path C:\Temp2\Temp1.zip -DestinationPath C:\Temp2 -Force";
rc = system(command);
run;
SAS will execute an external command using cmd.exe (at least by default).
Anyway, can you try this from a cmd console:
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -ExecutionPolicy Unrestricted -Command $PSVersionTable
You may not need the full path to Powershell, but it shouldn't hurt. Obviously replace the full path with whatever is in your environment.
Then, in SAS:
filename cmd1 pipe "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -ExecutionPolicy Unrestricted -Command $PSVersionTable";
data _null_;
infile cmd1;
input;
put _infile_;
run;
In my environment, I get this on my desktop (laptop):
Name Value
---- -----
PSVersion 5.1.17134.407 <<<<<
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.407
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
But this on my SAS server:
Name Value
---- -----
CLRVersion 2.0.50727.5485
BuildVersion 6.1.7601.17514
PSVersion 2.0 <<<<<
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
Hitting Google ("powershell expand-archive not recognized"), it looks like Expand-Archive is a recent addition (Powershell 4?)
I can replicate your issue in my environment - it works from my desktop, but not from my SAS environment.
See if that's your problem. If so, there are various fixes, AFAIK all of them involving your SAS Administrator (install WinZip / 7-Zip, upgrade Powershell).
Hope this helps...
When running external commands, use the filename pipe method:
filename oscmd pipe "PowerShell Expand-Archive -Path C:\Temp2\Temp1.zip -DestinationPath C:\Temp2 -Force 2>&1";
data _null_;
infile oscmd;
input;
put _infile_;
run;
You will find all system responses in the SAS log (the 2>&1 redirects stderr to stdout).
@Nyfaria wrote:
I did this and got:
Expand-Archive : The term 'Expand-Archive' is not recognized as the name of a
cmdlet, function, script file, or operable program. Check the spelling of the
name, or if a path was included, verify that the path is correct and try again.
Which makes no sense, because It definitely is a cmdlet.
It clearly is not, in the context of the SAS session. If this is actually a command stored in a file, supply the absolute path to it.
Hi
Have you tried using a ZIP filename statement instead of using an extermal command? - here is a starting point:
As @Kurt_Bremser implied, a command session opened from SAS may differ from a command session opened from the desktop.
You can run other commands using the piped INFILE, such as SET, to know more about the system session available to SAS.
SAS will execute an external command using cmd.exe (at least by default).
Anyway, can you try this from a cmd console:
C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -ExecutionPolicy Unrestricted -Command $PSVersionTable
You may not need the full path to Powershell, but it shouldn't hurt. Obviously replace the full path with whatever is in your environment.
Then, in SAS:
filename cmd1 pipe "C:\Windows\system32\WindowsPowerShell\v1.0\powershell.exe -NoLogo -NoProfile -ExecutionPolicy Unrestricted -Command $PSVersionTable";
data _null_;
infile cmd1;
input;
put _infile_;
run;
In my environment, I get this on my desktop (laptop):
Name Value
---- -----
PSVersion 5.1.17134.407 <<<<<
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.17134.407
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
But this on my SAS server:
Name Value
---- -----
CLRVersion 2.0.50727.5485
BuildVersion 6.1.7601.17514
PSVersion 2.0 <<<<<
WSManStackVersion 2.0
PSCompatibleVersions {1.0, 2.0}
SerializationVersion 1.1.0.1
PSRemotingProtocolVersion 2.1
Hitting Google ("powershell expand-archive not recognized"), it looks like Expand-Archive is a recent addition (Powershell 4?)
I can replicate your issue in my environment - it works from my desktop, but not from my SAS environment.
See if that's your problem. If so, there are various fixes, AFAIK all of them involving your SAS Administrator (install WinZip / 7-Zip, upgrade Powershell).
Hope this helps...
Hi, the compress-archive and expand-archive cmdlets are only implemented in Version 5.0 or later of Powershell
You can determine your PS Version by typing $psversiontable on the machine on which SAS is being run
- Cheers -
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.