I tried:
... sas.exe myfile.sas7bdat
without success.
I.e., I like to open a .sas7bdat file from the command line similar to how Windows opens SAS when double-clicking on a .sas7dbat file in Windows Explorer.
Thank you.
Sorry, I should have been more clear. Yes, I included the full path of sas.exe:
[full path]\sas.exe myfile.sas7bdat (this doesn't work)
If I exclude the filename (myfile.sas7bdat), then SAS starts up correctly.
Hello @sasmhe1,
On my computer, using Windows SAS 9.4M5, the below command opens dataset WANT (from folder C:\Temp) in a VIEWTABLE window of an open SAS session (or a new SAS session if none is already open):
"C:\Program Files\SASHome\SASFoundation\9.4\core\sasexe\sasoact.exe" action=Browse datatype=Data filename="C:\Temp\want.sas7bdat"
See the SAS GF 2013 paper "Double-Clicking a SAS® File: What Happens Next?" for more details, in particular the difference between sas.exe and sasoact.exe.
Personally, I prefer the SAS Universal Viewer (see https://support.sas.com/downloads/browse.htm?fil=&cat=74 -- it is not installed by default) in those rare situations when I want to scroll through a dataset. I'm using version 1.42 (which is not the most recent one) and the corresponding command looks like this:
"C:\Program Files\SASHome\SASUniversalViewer\1.4\SAS.UniViewer.exe" "C:\Temp\want.sas7bdat"
That cannot work. If you run SAS with name from the command line you are telling it what SAS program to run. Trying to interpret a SAS dataset as a program is not going to work. Just trying to read it as plain text file is not work either.
If you have SAS installed on Windows then check your Windows registry for what action the double click is mapped to.
If you cannot figure it out then just use the -INITCMD option instead to run some SAS code to make a libref and open VIEWTABLE to look at the file.
...\sas.exe -initcmd 'libname here "."; dm "viewtable here.myfile";'
To answer several posts.
I have two drives:
a slow high-capacity drive (s:) that holds many large datasets: ds1.sas7bdat, ds2.sas7bdat, ...
a fast smaller-capacity drive (f:) that can hold the largest dataset on s:
To work on a dataset, e.g., ds2.sas7bdat, I currently:
delete all files on f: (to make room)
copy s:\ds2.sas7bdat to drive f: (may take a long time)
start SAS 9.4 for Windows
in the Explorer pane, double-click on "This PC"
navigate to f:\ds2.sas7bdat, and double-click on it
(the data displays, allowing me to look at it, etc.)
Instead, I like to write a .bat file for each dataset in s: to automate the above process. E.g., ds2.bat might contain:
delete f:\*.*
copy s:\ds2.sas7bdat f:\
(a command that starts SAS 9.4 for Windows, selects ds2.sas7dbat and opens it)
I tried:
"C:\Program Files\SASHome\SASFoundation\9.4\core\sasexe\sasoact.exe" action=Browse datatype=Data filename="f:\ds2.sas7bdat"
but it didn't work.
Regarding Tom's suggestion using -initcmd, I don't understand the 'libname here "." ...' term.
My preference is to use a command that works without depending on any setting in the registry, or any Windows file type association, if that's possible.
Thanks to all.
Libraries are a basic component of data management in SAS. They are partially a short hand for pointing to the operating system's files.
If you open a SAS data set by clicking on the file in your file manager and SAS opens and displays it then it is extremely likely that SAS assigned a Library, typically with a name like TMP1 for the first file.
Then that data set, or others in the same physical location, could be used by procedures or data step code by referencing TMP1.<name> where name is the file name without the SAS7BDAT extension.
So what was recommended was for YOU to provide a LIBNAME statement, which looks like : Libname Mylib "path to folder"; So that you can then refer to the data set with commands like Viewtable as Viewtable Mylib.myfile; This is a very core very beginning concept in using SAS.
What else are you going to do with the data set besides view it? Any file that is large enough that you need to clear any significant amount of disk space to use then viewing it is pretty limited as to what you can do.
Thank you, ballardw.
I'm hoping it's not necessary to specify a folder path (in addition to the full path of the .sas7bdat file name) to make this work, as the .sas7bdat files are in different folders on different drives. Of course if this is necessary, then so be it.
Right now, I don't understand the LIBNAME statement enough to incorporate it into a complete .bat command line.
So I'll try to look into LIBNAME to learn about it.
Thank you again for your response.
@sasmhe1 wrote:I tried:
"C:\Program Files\SASHome\SASFoundation\9.4\core\sasexe\sasoact.exe" action=Browse datatype=Data filename="f:\ds2.sas7bdat"
but it didn't work.
What happened when you submitted that command? Did it open a new SAS session or did a running SAS session react? Did you get an error message from cmd.exe (e.g., saying that the path was misspelled or not found) or from SAS (e.g., saying that f:\ds2.sas7bdat does not exist)?
What is the content of the Windows registry keys
HKEY_CLASSES_ROOT\SAS.DataSet.701\shell\Browse\command
and
HKEY_CLASSES_ROOT\SAS.DataSet.701\shell\BrowsewithSAS940\command
(see the SAS GF 2013 paper I linked to for step-by-step instructions)?
Does the command work with .sas7bdat files on other drives?
Have you tried the SAS Universal Viewer?
When I submitted the command, there was NO response. No error message, no program started.
I tried entering the command manually at the command prompt:
cd .......\sasexe
sasoact.exe action=Browse datatype=Data filename="f:\Test\ds2.sas7bdat"
(no response, no error message, just a cmd prompt for a new command)
(and the command doesn't work on other drives)
Thank you for the "Double-clicking a SAS file" link, as it's clearly pertinent to my question.
Apparently my hope for a stand-on-its-own (registry-free) .bat command is unlikely.
In any case, as this isn't a top priority, I'll try revisiting when time permits, perhaps next week or so.
No, I didn't try the SAS Universal Viewer. Maybe later.
Thank you again for your input.
Was a LOG file created? Look for a file with an extension of LOG in folder that you executed from.
If you find one open it a text file, copy the contents and paste it into text box opened with </> icon above the message window.
Or
You need to understand how the LIBNAME statement works if you want to work with SAS data and code. It is a very simple concept (as old as original IBM computer systems). You pick a name you like to use. A short simple name. And assign it to the location where the files you want use live. Then instead of typing the full name of the file you can just type the nice simple short name.
So if you have file with a long name like: c:\myprojects\projext47\input_data\fred.sas7bdat
You can point a libref to the front part of that name, called the path or folder or directory.
libname mylib 'c:\myprojects\projext47\input_data\';
Then in your SAS code when you want to refer to that file you just use:
mylib.fred
And if there are other SAS datasets in the directory you can reference them using that same libref.
As to the example I posted a path of just a single period is the normal way to reference the current working directory. So if you want a command to run to browse a file I would assume you now how to change the current working directory to where the file is so you don't have to re-type the full directory name every time you want to run a command against one of the files in that directory.
So looking at your examples you might do something like this in the WIndows command window:
f: cd f:\ copy s:\ds2.sas7bdat . sas -initstmt "libname here '.'; dm 'viewtable here.ds2';"
If you really only have a few datasets at a time in the folder then perhaps it will be easier to just the EXPROOT command to open an Explorer window that will let you click on the file you want look at.
So something like:
sas -initcmd "exproot dir='.'"
Or perhaps hard code the path:
sas -initcmd "exproot dir='f:\'"
Here is what it looks like running on Unix with X windows.
So I moved the Documents folder and ran
sas -initcmd "exproot dir='.'"
And the window in the middle with the list of filenames opened. I was then able to use the mouse to open the SAS program that was there and one of the SAS datasets.
The command line syntax is the same on Windows.
"c:\Program Files"\SASHome_M7\SASFoundation\9.4\sas.exe -initcmd 'exproot dir="."'
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
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.
Ready to level-up your skills? Choose your own adventure.