1
votes

On several occasions, I've needed to run a procedure in SAS, then save output variables for access by another program (MATLAB). This is easy, for example:

proc genmod order=data;
    class X Y Z;
    output out= gmout1 prob = PRED;
    model count=X Y Z /dist=poi pred;
run; *mutual independence;
proc export data = work.gmout1
    outfile = "...\genmodout1.txt"
    dbms = csv replace;
run;

The output out= gmout1 in the 3rd line saves whatever variables proc genmod exports into a library table called gmout1.

My current need is to be able to access some of the data stored in gmout1 within SAS itself. Should be easy, but my searches have not turned up anything useful.

1
What are you trying to do with gmout1 in SAS?Joe
I need to run a proc which generates some variables and use them for further calculations. For example, genmod fits and estimates a generalize linear model. The result output to the screen includes model coefficients and fit statistics. I need to use some of these variables for further calculations. I'm using gmout1 then as a place to put them from genmod, so something else can get to them.Dr. Andrew

1 Answers

1
votes

Your dataset gmout1 can be used as the input for other procs using the data option. For example, if you want to print these:

proc print data=gmout1;
var _all_;
run;

You can also make modifications to the data through the data step (where most programming in SAS takes place) using the set statement. For example, if you have a variable "fit" and you need to recode that to be x100, you could do:

data gmout2; *creates new dataset gmout2;
set gmout1; *use the dataset gmout1;
new_fit = fit * 100;*creates new variable new_fit as 100 times fit;
run;

To export a specific variable (or variables) to a text file, you have multiple options. The easiest:

data _null_;
set gmout1;
file "c:\temp\myfile.csv" dlm=',' lrecl=32767 dsd;
if dimension="Value" and dimension2="Value";
put
variable1_numeric
variable2_character $
variable3_numeric
;
run;

I note you mentioned matrix - technically base SAS doesn't operate with matrices, only datasets (basically rows of data). SAS/IML is the matrix language; its usage is similar to R, and allows common matrix syntax.