Clustermembers on SPDS 4.3 - sas

I am working with clustered datasets on SPDS 4.3.
I want to generate a list of the members for each cluster.
I found two possibilities to get the information I am looking for.
Either by using PROC CONTENTS and have a look on field "Cluster members are" or by using PROC SPDO like this:
PROC SPDO LIBRARY=P30C033;
CLUSTER LIST LD_LIQ_CLUS_Customer;
QUIT;
In both cases I get the information in form of a report.
But I would like to get the information in form of a dataset.
I already tried out= and out2= on PROC CONTENTS, but dont get the desired output.
I also searchd for options to PROC SPDO CLUSTER LIST, but with no result.
Thx in advance
MiKe

As a generic answer for any PROC, you can use ODS OUTPUT to get the dataset even if you can't use OUT= .
Add ODS TRACE ON; before the proc runs (and ODS TRACE OFF after it). It should give you some results in the log telling you what the output is named; you can then use ODS OUTPUT to get the results.
For example, with PROC CONTENTS, run:
ods trace on;
proc contents data=sashelp.class;
run;
ods trace off;
Mabe you see that the VARIABLES table looks interesting to you. So run:
ods output Variables=sasvars;
proc contents data=sashelp.class;
run;
ods output close;
ODS TRACE is not needed if you already know the name of the output portion, of course.

You can use ODS OUTPUT CLUSTERLIST= as shown in the below code example:
ods noresults;
ods output clusterlist=WORK.CLUSTER_MEMS;
proc spdo lib=SPDSLIB;
cluster list CLUSTER1;
cluster list CLUSTER2;
/* ... */
cluster list CLUSTERN;
quit;
ods output close;
ods results;
This allows you to capture one or multiple clusters' members into a single data set.
You can also capture cluster members to separate data sets using OUT= option:
proc spdo lib=SPDSLIB;
cluster list CLUSTER1 out=CLUSTER1_MEMBERS;
cluster list CLUSTER2 out=CLUSTER2_MEMBERS;
/* ... */
cluster list CLUSTERN out=CLUSTERN_MEMBERS;
quit;
For more on this topic see my recent blog post How to retrieve contents of a SASĀ® Scalable Performance Data Server library.

Related

Store the value generated by PROC FREQ

The PROC Freq function generates a frequency table with the percentage, and the frequency of the variables. Is there a way to store the percentage of the variable for later use (like use this value to create dataset, create graphs)?
ODS OUTPUT is your friend any time you want to take the results of a PROC. Many procs, including PROC FREQ, also have output options built-in, but the generic one is ODS OUTPUT.
First, use ODS TRACE to identify the (internal to SAS) name of the table you need.
ods trace on;
proc freq data=sashelp.class;
tables age;
run;
ods trace off;
This generates:
Output Added:
-------------
Name: OneWayFreqs
Label: One-Way Frequencies
Template: Base.Freq.OneWayFreqs
Path: Freq.Table1.OneWayFreqs
-------------
Now you can use that with ods output:
ods output OneWayFreqs=myfreqdata;
proc freq data=sashelp.class;
tables age;
run;
ods output close; *this is technically not needed, but I like to have it for clarity;
It will make a table called myfreqdata (name that something useful please!). It isn't always "pretty"; sometimes you are better off using the built in output options in a proc, because they're more usefully formatted, but usually you can get somewhere from it.
Good afternoon,
It sounds like you want to output the results of the PROC FREQ to a SAS dataset. This will allow you to use them later, whether it is for further analysis or visualization. To do that, simply pass the a dataset name to the out= option after the table statement. You will notice below I also used the noprint option. This avoids needlessly printing the table.
For example,
proc freq data=work.dataset noprint;
table var1*var2 / out=work.output_data;
run;
I hope this helps!

SAS only include chi-square output in proc freq

I'm using the following code to do a chi-square test in SAS.
proc freq data=data;
tables var1*var2/chisq;
run;
It gives the output of both chi-square and Fisher's Test. Anyway to only include chi-square test in the output?
You can use ODS SELECT/EXCLUDE to control what is displayed. If you don't want the fishers test you can exclude that table, assuming the table name is FISHERSEXACT.
ods exclude fishersexact;
Alternatively you can select in only the tables you want and everything else is excluded by default.
ods select crosstabfreqs chisquare;
I do not think you can supress printing some of the tables in PROC FREQ; it seems to me you can supress all, or none.
However, still you can work as follows:
First, do a one-off investigation: issue the ods trace on / label before your statement so that the Log contains labels of the ODS tables:
ods trace on / label;
proc freq data=data;
tables var1*var2/chisq;
run;
ods trace off;
Alternatively, find the name of your table in PROC FREQ docs.
Once you know the table name, run your code again but this time save the respective ODS table to a regular table. This is done by issuing ods output <ODS=table-name>= <table-to-save-it-into>; in front of your command. Assuming you want to save the ChiSq table the code looks like:
ods output ChiSq=work.my_chisq_table;
proc freq data=data;
tables var1*var2/chisq;
run;
The chi-square table will be saved as work.my_chisq_table and you can print it elsewhere.

SAS suppress .lst files but keep ODS output

I was doing a PCA analysis with SAS using the following code:
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) NOPRINT;
id time;
run;
ods output close;
Because the lst files this analysis produces is too large, I used the NOPRINT option. However, it seems that the NOPRINT option also eliminates all of my ODS outputs. (Now PRINCEEV and PRINCEEVAL are all empty):
ERROR: File WORK.PRINCEEVAL.DATA does not exist.
ERROR: Export unsuccessful. See SAS Log for details.
259 putn
_______
1
259 ! ame=YES; run;
WARNING 1-322: Assuming the symbol PUTNAMES was misspelled as putname.
ERROR: File WORK.PRINCEEV.DATA does not exist.
ERROR: Export unsuccessful. See SAS Log for details.
ERROR: Errors printed on page 1.
Is there a way to suppress the generation of lst file, without affecting the ods output?
UPDATE:
It seems that according to the following sas blog, it is not possible to do that:
Can you combine NOPRINT and ODS OUTPUT?
SAS programmers crave efficiency. Upon reading that the NOPRINT option
can make a procedure run faster, the ambitious programmer might
attempt to run a procedure with the NOPRINT option but use the ODS
OUTPUT statement to capture the results of one table. Sorry, friend,
but you can't do that. The NOPRINT option means that no ODS tables are
created, so there is no way to select a table and save it to a data
set.
But the dilemma is, I have limited space on the cloud computing server. The lst files are doing nothing but wasting my spaces. Deleting the lst files when SAS programs are running with external processes will also produce an io error in SAS (I already tried that).
Is there anyway around?
I would suggest:
ods listing close ;
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) NOPRINT;
id time;
run;
ods output close;
This will close the listing destination, so should work fine.
I noticed in a related blog post, Rick argued for:
ods exclude _all_ ;
http://blogs.sas.com/content/iml/2015/05/28/five-reasons-ods-exclude.html
Minor change to the previous answer: remove the NOPRINT option and after the ODS OUTPUT is created open up the ods listing if you have further code.
ods listing close ;
ods output Eigenvectors=PRINCEEV Eigenvalues=PRINCEEVAL;
proc princomp data=REPLACED PLOTS=SCORE(ELLIPSE NCOMP=5) /*NOPRINT*/;
id time;
run;
ods output close;
ODS LISTING;
If you execute your sas-script on your cloud computing server via bash, then you can send your .lst files to /dev/null:
sas -print /dev/null script.sas
The -print option only effects your .lst, but not any ODS related outputs.

Output to new data set

Suppose that I have a model and I want to output the studentized residuals, leverages, Cook's Distance and the DFFITS statistics from my regression model to a new data set. How would I do this?
Answering as a general question of how do I get certain pieces of output from a proc to a dataset, you will want to look at ODS TRACE.
ods trace on;
proc reg <stuff>;
<stuff>;
run;
ods trace off;
Now, look at the log, and see what different output options you have. All of the different things that go to the screen will be here, plus additional tables sometimes that don't go to any output window by default. Find the name for the tables you want data from, and then direct them to an ods output statement.
ods output <name>=<datasetname>;
proc reg <stuff>;
<stuff>;
run;
ods output close;
You can specify multiple names and multiple output datasets, assuming you want more than one thing.

How to export selected p-values to the table in SAS?

I'm trying to write a program in SAS that supports decision-making process in selecting the best formula of linear regression model. I even had one but in R environment. Now I have to implement it in SAS. The final result should be a dataset with each line decribing different regression formulas i.e. names of explanatory variables, R-squared, p-values for different statistical tests, etc.
As an example, one of the tests is Durbin-Watson test for autocorrelation. My goal is to insert a p-value into the table I've mentioned. I use the code:
proc reg data=indata outest=outdata EDF ridge=0 OUTVIF;
model PKB = PK INV SI / DW;
run;
quit;
And as a result I get in the output window:
Durbin-Watson Statistics
Order DW Pr < DW Pr > DW
1 1.2512 0.0038 0.9962
I want to insert those p-values directly into the SAS table. I tried to find an answer in the SAS OnlineDoc and on the forum but with no success.
ODS OUTPUT is the best way to get information that you can print to the screen into datasets. Use ODS TRACE ON; before your code, run it, then inspect the log; see what table name matches what you're looking for. Then use ODS OUTPUT <tablename>=<datasetname>.
For example, in this PROC FREQ, I see ONEWAYFREQS is the table I want.
ods trace on;
proc freq data=sashelp.class;
var age;
run;
ods trace off;
So I use ODS OUTPUT:
ods output onewayfreqs=ages;
proc freq data=sashelp.class;
table age;
run;
ods output close;
and get a nice dataset. (ODS TRACE is not necessary if you know the name of the table you're looking for.)