'Header' File in SAS? - sas

Is there a way to run a sas program with an external 'header' file (similar to python? For example, in python I can put 'import var_names.py' at the top of main.py, and change what I want in var_names.py instead of having to alter main.py. Is there something similar for SAS? Thank you!

It sounds as though you are looking for the %include statement.
Official documentation:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/a000214504.htm
You can also re-use code in various other ways, e.g. by defining macros and saving them to an autocall folder, saving formats to catalogues, and custom data step functions (via proc fcmp).

Related

SAS Enterprise Guide export as step in process path selection

As part of the SAS Enterprise Guide export as a step in process the outhput file location is very tedious to select. Is there any faster way to do it than clicking through all the folders on my harddrive for every export.
The path is shown but I am not able to edit the path or paste a path here:
And when i press browse I am still not able to paste a path:
Am I doing something wrong, missing a setting or is there some kind of workaround.
Temporary question to Joe:
Like this?
Here is the most basic example of a macro, that can export your tables as excel files:
%macro ExportExcel(path,file_name,tab_name);
proc export data=&tab_name
outfile="&path.&file_name..xlsx"
dbms=xlsx
replace;
run;
%mend;
You can just paste your path, or better yet, make it a macro variable using %let statement.
But depending on your needs you can make this macro way more complicated. You can put more than one table into a single .xlsx file on different sheets, using a sheet statement. You can export every table from a whole library. It really depends on what you want.
You should be able to paste a full path into the filename box, just as with any other "save" dialog. This certainly works with the current version (Enterprise Guide 8.3), but should work with older versions as well.

Change temporary file directory in SAS

I need to use PROC.SQL statements for my analysis. The problem is, SAS uses C disk in order to create temporary files when I use SQL statements. My datasets are very large and I do not have enough space for that. Could you please explain me how to allocate this temporary file in other place rather than C disk?
You want to change the WORK system option. You can do:
c:\sas\sas.exe -work d:\temp
to use the d:\temp directory.
You can also use the OPTIONS statement within the config file used when starting SAS (thanks Tom):
options work='d:\temp'
See also:
Indiana University answer for SAS on UNIX systems.
SAS 9.2 documentation on system options.
Create a 'user' library instead. When a USER library is in effect, all one level datasets are written to this directory and it's used as the default instead of WORK library.
libname user 'path to other location';
If you want to permanently change sas work location, you can set it in sasv9.cfg. (Default location: C:\Program Files\SASHome\SASFoundation\9.4\nls\en\sasv9.cfg). Along with -WORK, you may also want to change the value for -UTILLOC option.
You can even spread a Load across Multiple Volumes of Different Disks. Please read Example 1 mentioned in this link - https://support.sas.com/documentation/cdl/en/hostwin/69955/HTML/default/viewer.htm#n1qr5dmzagn9krn1lt1c276963za.htm

Remove standard SAS libraries from GUI

I'd like to remove/delete/unassign the standard SAS libraries from my SAS 9.3 GUI.
I've tried two solutions to remove a library which haven't worked:
%sysfunc(libname(maps)) results in:
ERROR 180-322: Statement is not valid or it is used out of proper order.
Comment out the offending start up code in the file sasv9.cfg
I don't have permission to modify (C:\Program Files...) files in that directory
Thanks!
The libraries are:
- Maps
Mapsgfk
Mapssas
Sashelp
Sasuser
You can remove the map related libnames, at the cost of not having the map files available to you and possibly losing some functionality.
If you copy your basic config file to some other location, either to one of the predefined locations mentioned in Files Used By SAS for your operating system (I link to the Windows version here, but Unix has a similar page); or to a location specified on the -CONFIG option in your shortcut, like for example:
"C:\Program Files\SAS94\SASFoundation\9.4\sas.exe" -CONFIG "C:\temp\sasv9_nolibs.cfg"
You can do this without having write access to the Program Files directories where the config files are usually stored. If you do that, you can then customize it by removing the -MAPS and related lines. Then those libraries will not be created; in that case, only SASHELP, SASUSER, and WORK are created, as follows:
Removing SASUSER does not seem to be possible, as while you can remove the -SASUSER option in the config file, it will still create the SASUSER folder.
Removing the -SASHELP option will unfortunately cause SAS to crash on initialization; SASHELP contains many core files for SAS functionality and SAS cannot work without it. See the following screenshot.
As such, you can get down to 3 libraries, but not further.
You got the 180-322 because the libname function returns a value and you call it in open code and the code it generated is not valid.
29 %put NOTE: %sysfunc(libname(maps));
NOTE: -630193
Do as above an you will see the value. However it looks like you cannot clear LIBREF MAPS.
Not sure if you can remove them without changing your system wide config.sas file. But you could point the MAPS options to null devices so that they don't find any datasets. Here is output from PROC OPTIONS.
MAPS=!SASROOT/maps
Specifies the location of SAS/GRAPH map data sets.
MAPSGFK=!SASROOT/mapsgfk
Specifies the location of GfK maps.
MAPSSAS=!SASROOT/maps
Specifies the location of SAS map data sets.
You can point these two different locations with command line options.
sas -maps /dev/nul -mapsgfk /dev/nul -mapssas /dev/nul
The libref will still be created but there won't be any members found.
You might do something similar for SASUSER, but then you would probably also want to add -rsasuser option so that SAS would know to create a WORK.PROFILE to use in place of the normal SASUSER.PROFILE catalog.
I don't think you would want to remove SASHELP libref as I think there are a number of things in SAS that would not work without being able to find things that are made available via that libref.

Is it possible to get a file modification time in Stata?

Suppose I have a database with file names and I would like add file modification dates and times to this database. Is it possible to do it in Stata in a straightforward way?
I can think of two non-straightforward ways:
1) Writing a plugin in C or Java.
2) Using dir command, capturing the output in a log file, and then importing that log file back.
But is there a less cumbersome solution?
There does not seem to be either a Stata or a Mata function that is of any help. I realize that I can easily do it in any scripting language and then import the results into Stata but I would like to know if there is a purely Stata solution (for portability reasons).
I think you can do that using the shell capabilities of Stata.
See here:
http://www.stata.com/help.cgi?shell

How can I read/convert SAS Gov't Data files on a MAC?

There are gov't data files: http://www.cdc.gov/EpiInfo/
Available in this weird SAS format. How can I convert them into XML/CSV, something much simpler that can be read by scripts/etc.???
I had the same problem, so i made a simple SAS data viewer. You download it from the downloads section here: http://code.google.com/p/sasquatch
It has alot of the same features as SAS Universal Viewer, but its still a work in progress.
You need to have Adobe AIR installed, you can get that on the adobe website.
Are the data in the SAS XPORT (.xpt) or .sas7bdat format?
For future reference, SAS XPORT files can be read and written using the 'SASxport' package for R (http://cran.r-project.org/web/packages/SASxport/index.html).
(Already posted this to superuser.com)
SAS Institute (the company that makes SAS) produces a viewer for SAS data sets.
Note that SAS program files usually have the extension .sas, whereas the data files themselves usually have the extension .sas7bdat.
(EDIT: I notice belatedly that your title says on a Mac, so this may not help much as I believe the tool is Windows only.)
Here a quick-and-dirty python five-liner to convert a SAS .xpt (aka XPORT) file to .csv
import pandas as pd
FILE_PATH = "(fully qualified name of directory containing file)"
FILE = "ABC" # filename itself (without suffix)
# Note: might need to substitute the column name of the index (in quotes) for "None" here
df = pd.read_sas(FILE_PATH + FILE + '.XPT', index=None)
df.to_csv(FILE_PATH + FILE + '.csv')
Hopefully this might help someone
JMP runs on MAC and can read sas files. Visit jmp.com for more information.
There are two parts to your question
1. Read these files
2. Convert these files
I looked into the link you shared there are no directly downloadable files, but I am assuming that you mean the files for windows.
For viewing you can use the folloiwng
a. SAS Universal viewer: https://support.sas.com/downloads/package.htm?pid=667
b. Use SAS on mac to directly read the files
For conversion you can do the following
a. Use SAS proc import to export and proc export to export the files feature,
b. Use third party softwares, e.g., DBMSCopy for this;
c. Download trial version of JMP and convert the files to desired format, e.g., CSV/txt etc and get done with it.