Creating a matrix using proc iml in sas eg - sas

When you submit a PROC IML in SAS EG it appends a QUIT statement to the program, this quit statement terminates the procedure and deletes all previously computed matrices.
Does anyone know a workaround?

You should use SAS/IML Studio. That is the IML version of enterprise guide; it should allow you to connect to a SAS Workspace server, if you're not running in local.
See Getting Started with the SAS/IML Language by Rick Wicklin (2013 SGF paper) for more details.

Related

SAS : ODS and code highlighting

When using R markdown for making statistical reports, I have the ability to echo the R code in my output document. I'm learning SAS and I was wondering if it was possible to highlight or echo the SAS code in my final ODS report ? I'm using a dirty hack right know to display the code in my document, which is using "ods text = ", but it seems quite redundant. Plus it doesn't add syntax highlighting.
That feature does not exist in the SAS language right now, but it has been mentioned in several talks by Amy Peters, principal product manager of the SAS programing environments, as a planned feature for a near-future SAS release (with no specific date yet, but hopefully in the next 2 years). It would likely be implemented in a similar fashion to Jupyter Notebooks, in that you write your code and get your output inline.
That said, SAS does support Jupyter Notebooks, which is the best current (third party) solution. Contact your SAS administrator for more information.
I have an idea here, I'm the type of guy who dosent take no for answer and find a way to fiddle and get it done... but i think this is abit far fetch... you can try still I think it will work with mostly evrything but may have a hard time to play with quotes when you have multiple semi colomns....
Check:
I started by creating a dumbass dataset :
data tata;
x=1;
run;
then we do the following:
%let code= select * from tata;
proc sql;
create table report as
&code.;
quit;
proc print data=report;
footnote "&code.";
run;
The rationale:
I think it you put your code in macrovariables and then execute those macro variables you would be able to print show the code after by printing the macrovariable following your text...
See the sample

How to find SAS version from SAS Enterprise Guide?

In my previous work place where I had access to base SAS (running SAS interactively on the server directly), I could find out the current SAS version easily (from the SAS log) by issuing the code proc setinit; run;
In my new work place there is no base SAS - only Enterprise Guide. I try running the same code but the SAS version does not appear in the SAS log.
I would like to easily find out the SAS version running on the server from Enterprise Guide. Is this possible or not? If so, how?
The values you're looking for are stored in automatic macro variables in your system. The code below retrieves the macro variables and prints them to the log for your information.
%put ** my information;
%put short version: &sysver;
%put version: &sysvlong4;
%put site #: &syssite;
%put cpu: &sysscp &sysscpl;
EDIT: Update answer
You can use PROC PRODUCT_STATUS which is great, since it will print the relevant information to the log.
proc product_status;run;
There are some other options available rather than using the global macro variables (&sysver and &sysvlong4), if you prefer point-click options.
First, under Help -> About SAS Enterprise Guide, if you select 'Configuration Details' you can see your SAS system version.
Second, if you select the server in the Servers tree (in the window on the bottom left), and right click->Properties, you will see the SAS version/etc. information.
Third, if you continue in that and select "View Initialization Log", it will show you the initialization log (the bit SAS shows when you start a session in the log). This includes the version number and some other useful information.
Just run the following code and all available information will be printed automatically.
proc setinit;
run;
You can also use
%put _all_;
that will display all macro variables available in your session.
proc setinit;
run;
You can run this set of code and check the results. It will tell you the version you are using.
%put &_clientversion; gives you version.
proc setinit;
run;
Or under the help tab in the top left of the enterprise guide.

sas enterprise 5.1 guide export to excel template

I'm having a wee bit of a problem and I was hoping someone out there has a magic solution.
At present we run a bit of code on SAS 9.3 that uses DDE to populate an excel template - populating text from cells B2:M24 - these are character or text fields with no formulae. This does work, but we're moving to Enterprise Guide 5.1 and I need something that will work on there.
I'm pretty new to Enterprise Guide and I've googled this until my head is about to explode and so far, nothing has worked. We can't just do a manual export as this will be a scheduled job.
Presumably there is a way to do this that I'm missing. Can anyone point me in the right direction please?
Managed to get it done through PC Files server using named range in Excel.
libname xls PCFILES path="C:\Template.xls" server=<Server> port=<port>
user= pass= ;
proc datasets lib=xls nolist;
delete <named range>;
quit;
data xls.<named range>;
set <named range>;
run;
libname xls clear;
Probably not the most elegant way but it got the job done.
Thanks anyway.

Error W/ PROC GEOCODE

Hopefully someone out there will have run into this before. I'm trying to use the street level geocoding capability of SAS' PROC GEOCODE, but I keep getting a cryptic error. I couldn't find anything on the net about it (although to be fair I only spent a half hour looking).
First, I'm using SAS Enterprise Guide (I've tried on both v4.2 and v4.3), although I still prefer to program as I find the point and click interface quite limiting. Maybe this right here is my problem?
Anyway I first get the lookup data sets from http://support.sas.com/rnd/datavisualization/mapsonline/html/geocode.html and follow the instructions in the readme. I also use the pre-written SAS program to import the CSV files. My input dataset contains just 4 variables: street address, city, state, and zip. I then run the following code:
libname josh 'C:\Users\Josh\Desktop\Geocode\SAS files';
proc geocode
method=street
data=SASUSER.Home_Policy_Address_Detail
lookupstreet=josh.USM
out=test;
run;
However I get this error:
ERROR: Variable NAMENC not found in JOSH.USM data set.
Nowhere in the readme or the import program is a variable named "NAMENC" ever mentioned. This is what has me stumped. Is it something wrong with the simple PROC GEOCODE program I wrote? Is it due to me using SAS EG (although I've yet to run into a base SAS procedure that hasn't worked on EG)? Or something else?
Any help/guidance would be much appreciated. Thanks in advance!
Check your SAS version. You can use the 'Help' menu in DMS mode or submit this statement:
%put &sysvlong;
It looks like you are using SAS 9.3 but your lookup data JOSH.USM is the lookup data formatted for SAS 9.4.
PROC GEOCODE street lookup data comes in two slightly different formats, one for SAS 9.3 and another for 9.4. When you download the nationwide lookup data from the SAS MapsOnline geocoding page, make sure to download the version appropriate for your SAS release.

How can I read a SAS dataset?

I have a lot of files in SAS format, and I'd like to be able to read them in programs outside of SAS. I don't have anything except the base SAS system installed. I could manually convert each one, but I'd like a way to do it automatically.
You'll need to have a running SAS session to act as a data server. You can then access the SAS data using ODBC, see the SAS ODBC drivers guide.
To get the local SAS ODBC server running, you need to:
Define your SAS ODBC server setup at described in the SAS ODBC drivers guide. In the example that follows, I'll connect to a server that is set up with the name "loclodbc".
Add an entry in your services file, (C:\WINDOWS\system32\drivers\etc\services), like this:
loclodbc 9191/tcp
...set the port number (here: 9191) so that it fits into your local setup. The name of the service "loclodbc" must match the server name as defined in the ODBC setup. Note that the term "Server" has nothing to do with the physical host name of your PC.
Your SAS ODBC server is now ready to run, but is has no assigned data resources available. Normally you would set this in the "Libraries" tab in the SAS ODBC setup process, but since you want to point to data sources "on the fly", we omit this.
From your client application you can now connect to the SAS ODBC server, point to the data resources you want to access, and fetch the data.
The way SAS points to data resources is through the concept of the "LIBNAME". A libname is a logical pointer to a collection of data.
Thus
LIBNAME sasadhoc 'C:\sasdatafolder';
assigns the folder "C:\sasdatafolder" the logical handle "sasiodat".
If you from within SAS want access to the data residing in the SAS data table file "C:\sasdatafolder\test.sas7bdat", you would do something like this:
LIBNAME sasadhoc 'C:\sasdatafolder';
PROC SQL;
CREATE TABLE WORK.test as
SELECT *
FROM sasadhoc.test
;
QUIT;
So what we need to do is to tell our SAS ODBC server to assign a libname to C:\sasdatafolder, from our client application. We can do this by sending it this resource allocation request on start up, by using the DBCONINIT parameter.
I've made some sample code for doing this. My sample code is also written in the BASE SAS language. Since there are obviously more clever ways to access SAS data, than SAS connecting to SAS via ODBC, this code only serves as an example.
You should be able to take the useful bits and create your own solution in the programming environment you're using...
SAS ODBC connection sample code:
PROC SQL;
CONNECT TO ODBC(DSN=loclodbc DBCONINIT="libname sasadhoc 'c:\sasdatafolder'");
CREATE TABLE temp_sas AS
SELECT * FROM CONNECTION TO ODBC(SELECT * FROM sasadhoc.test);
QUIT;
The magic happens in the "CONNECT TO ODBC..." part of the code, assigning a libname to the folder where the needed data resides.
There's now a python package that will allow you to read .sas7bdat files, or convert them to csv if you prefer
https://pypi.python.org/pypi/sas7bdat
You could make a SAS-to-CSV conversion program.
Save the following in sas_to_csv.sas:
proc export data=&sysparm
outfile=stdout dbms=csv;
run;
Then, assuming you want to access libname.dataset, call this program as follows:
sas sas_to_csv -noterminal -sysparm "libname.dataset"
The SAS data is converted to CSV that can be piped into Python. In Python, it would be easy enough to generate the "libname.dataset" parameters programmatically.
I have never tried http://www.oview.co.uk/dsread/, but it might be what you're looking for: "a simple command-line utility for working with datasets in the SAS7BDAT file format." But do note "This software should be considered experimental and is not guaranteed to be accurate. You use it at your own risk. It will only work on uncompressed Windows-format SAS7BDAT files for now. "
I think you might be able to use ADO,
See the SAS support site for more details.
Disclaimer:
I haven't looked at this for a while
I'm not 100% sure that this doesn't require additional licensing
I'm not sure if you can do this using Python