BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Nyfaria
Fluorite | Level 6

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ScottBass
Rhodochrosite | Level 12

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...

 

 


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.

View solution in original post

9 REPLIES 9
Kurt_Bremser
Super User

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
Fluorite | Level 6
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.
Kurt_Bremser
Super User

@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.

ErikLund_Jensen
Rhodochrosite | Level 12

Hi

 

Have you tried using a ZIP filename statement instead of using an extermal command? - here is a starting point:

 

https://blogs.sas.com/content/sasdummy/2015/05/11/using-filename-zip-to-unzip-and-read-data-files-in...

Nyfaria
Fluorite | Level 6
This will not function well in my final product.
ChrisNZ
Tourmaline | Level 20

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.

ScottBass
Rhodochrosite | Level 12

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...

 

 


Please post your question as a self-contained data step in the form of "have" (source) and "want" (desired results).
I won't contribute to your post if I can't cut-and-paste your syntactically correct code into SAS.
Nyfaria
Fluorite | Level 6
You are my Hero! Thanks for being the First person in the history of my asking for help online to Actually Answer the question I asked and not try and make me do things in a different way because they like that way better.
Oligolas
Barite | Level 11

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 -

SAS Innovate 2025: Call for Content

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!

Submit your idea!

How to Concatenate Values

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.

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
  • 8439 views
  • 7 likes
  • 6 in conversation