Example: how to use ODS in PROC GLIMMIX or other procs

/*Use proc GLIMMIX to run an OLS regression
and saves results (parameter estiamtes) in a
data set named “john” using ODS*/
proc glimmix data=sashelp.class;
model height=weight /dist=normal link=identity solution;
ods output ParameterEstimates=john;
run;
/*Edit the result data*/
data john2;set john;

/*Create a new variable that indicates
the level of significance*/

/*Do not forget to specify a value length*/
length asterisk $ 3;

if Probt < 0.10 then asterisk=”~”;
if Probt < 0.05 then asterisk=”*”;
if Probt < 0.01 then asterisk=”**”;
if Probt < 0.001 then asterisk=”***”;

run;

/NOW FIND john2 in a work directory and right-click it
to open with Excel*/

/*You can also see this by PROC PRINT*/
proc print data=john2;
run;

ROC Curve Analysis using PROC LOGISTIC

/*ROC Curve Analysis Macro*/

/*a hypothetical data set*/
data asdf;set sashelp.class;
EVENT=0;
if Weight > 100 then EVENT=1;
PREDICTOR=height;
run;

/*data name*/
%let dataname=asdf;
%let outcome=EVENT;
%let ind=PREDICTOR;
%let save_graphic=C:\Documents and Settings\19702\My Documents\sas;

ods html PATH=”&save_graphic” (url=none) file=”&dataname &ind .html”;
ods graphics on / imagename=”&dataname&ind”;
proc logistic data=&dataname descending OUTEST=&dataname.result;
title “&dataname”;
model &outcome =
&ind
/ outroc=&dataname.kaz2 ROCEPS=0 ;
output out = m2 p = prob xbeta = logit ;
ods output ParameterEstimates=kazcoeff
Association=kazassoc
ConvergenceStatus=kazconverg(keep= reason);
run;
ods graphics off;
ods html close;

proc transpose data=kazassoc out=T1;
var cValue1;
id label1;
run;
proc transpose data=kazassoc out=T2;
var cValue2;
id label2;
run;

data kazassoc2;
merge T1 T2;
run;

/*ods trace off;*/
/*Get descriptive statistics*/

ods listing close;
proc means data=&dataname;
var
&outcome
&ind
;
ods output summary=uekawa;
run;
ods listing;
/*get significance of the independent varible*/
data kazcoeff2;
set kazcoeff;
if Variable=”&ind”;
keep ProbChiSq StdErr flag;
flag=1;
label ProbChiSq=”P-value for the ind var effect”;
label StdErr=”Stderr for the ind var effect”;
run;

data &dataname.kaz2;set &dataname.kaz2;
flag=1;
run;

data &dataname.result;
set &dataname.result;
flag=1;
run;

data &dataname.kaz3;merge &dataname.kaz2 &dataname.result kazcoeff2;
by flag;
run;

data &dataname.kaz4;set &dataname.kaz3;
Distance=sqrt( (0-_1MSPEC_)**2 + (1-_SENSIT_)**2 );
suji=_n_;
run;
proc sql;
create table &dataname.kaz5 as
select *,
min(distance) as minimum_distance
from &dataname.kaz4;
run;

data optimal;
retain CUT_OFF_VALUE;
set &dataname.kaz5;
CUTOFF=0;
if distance = minimum_distance then do; CUTOFF=1; type=”Dist to perfection”;end;
/*if distance2 = maximum_distance2 then do; CUTOFF=1;
type=”Dist to noninf”;end;*/
if cutoff=1;
effect=&ind ;
LOGIT=LOG(_PROB_ / (1-_PROB_));
CUT_OFF_VALUE=((LOGIT-Intercept)/effect);
drop cutoff ;
run;
data results_of_ROC;
merge optimal uekawa kazassoc2 kazconverg;

TRUE_POSITIVE_RATE=_SENSIT_;
TRUE_NEGATIVE_RATE=1-_1MSPEC_;
AUC=C;
run;

proc print data=results_of_ROC;
title “ROC stats for &outcome”;
var CUT_OFF_VALUE
TRUE_POSITIVE_RATE
TRUE_NEGATIVE_RATE
AUC ;
run;

How to read values separately off one variable that contains multiple information

Hello, I have a variable that includes multiple values, separated by commas. For example, I have a variable URBANICITY. For each subjects, I have values like this:

Urbanicity
Urban
Urban, Rural
Rural, Suburb
Suburb,
Urban, Rural, Suburb
***********

data old;
input Urbanicity $20.;
cards;
Urban
Urban, Rural
Rural, Suburb
Suburb
Urban, Rural, Suburb
;
run;

data temp;
set old;
numw=countw(urbanicity,’,’);
do i=1 to numw;
new_urban=scan(compress(urbanicity),i,’,’);
output;
end;
run;

proc print data=temp;
run;

proc freq data=temp;
tables new_urban;
run;
Thanks SAS!

Read a line of texts treating each word as a variable

I have a text file in which there are data entries like this:

apple orange fish meet kite stone

I want to create a SAS dataset like this:

VAR1 <– this is variable name.
apple
orange
fish

*************

Hi,

To read a record which contains multiple values and create multiple observations with 1 variable, you can use the INPUT statement with the double trailing @. I created a sample record with your data and then used the DATA step with INFILE and INPUT statement to read in the data to create multiple observations with 1 variable. Here is the code:

data one;
infile ‘c:\temp\input2.txt’;
input v1 $ @@;
run;

proc print;
run;

Here are the results from PROC PRINT:

Obs v1

1 apple
2 orange
3 fish
4 meet
5 kite
6 stone
<Thanks,AE>

Add letters to all variable names in a SAS dataset

Add prescript

%let old=sashelp.shoes;
%let new=newdataname; /*it is okay for the old name and the new name to be the same*/
%let prefix=abcd_;

data XXX;set &old;
run;
PROC SQL NOPRINT;
SELECT TRIM(NAME)||”=&prefix”||TRIM(NAME)
INTO :VARLIST SEPARATED BY ‘ ‘
FROM DICTIONARY.COLUMNS
WHERE LIBNAME EQ “WORK” AND MEMNAME EQ “XXX”
ORDER BY VARNUM;
QUIT;
PROC DATASETS LIBRARY=WORK NOLIST;
MODIFY XXX;
RENAME &VARLIST;
QUIT;
data &new;
set XXX;
run;

 

 

Add postscript

PROC SQL NOPRINT;
SELECT TRIM(NAME)||”=”||TRIM(NAME)||”&post”
INTO :VARLIST SEPARATED BY ‘ ‘
FROM DICTIONARY.COLUMNS
WHERE LIBNAME EQ “WORK” AND MEMNAME EQ “XXX”
ORDER BY VARNUM;
QUIT;

 

If you need some variables not renamed in this process, modify the where statement:

WHERE LIBNAME EQ “WORK” AND MEMNAME EQ “XXX”

and upcase(name)  ne ‘GENDER’

and upcase(name)  ne ‘ID’

and upcase(name)  ne ‘YEAR’