Friday, February 1, 2008

Use a sample to hasten preliminary analysis

I have used following ways;

**************************
proc surveyselect data=onenn method=srs n=10000 out=onen;
run;

**************************
data onen;
merge
fa7684 fa8694 fa9600 nur92 nur94 n94_dt
temp(in=mstr) nur96 nur98 act8600
nur82 nur88 n84_dt n86_dt n90_dt
fileb n767880 meddata
temp db7602
fatalmi mi stroke anginew
fatalstk deadff2004 pact spact end=_end_;

by id;
exrec=1;
if first.id and mstr then exrec=0; /*** mas = master file ie. n80_cf ***/
if famdb82=1 then famdb88=1;
else famdb88=0;
random=RANUNI(-1); /* GENERATE A RANDOM VECTOR */
%let k=5000;
run;

PROC SORT DATA=onen;
BY random; /* SORT OBSERVATIONS BY THE RANDOM VECTOR */
run;

DATA onensample;
SET onen(drop=random);
IF _N_ le &k; /* SELECT THE FIRST K OBSERVATIONS */
/*both magne

Wednesday, June 27, 2007

Concatenating sas macro variables

I always forget how to do it.

%let nagasuchi=cases;
data new;
set library.old&nagasuchi;

This would be read as
data new;
set library.oldcases;


If the macro variable is a prefix

data new;
set library.&nagasuchi.old;
/* note the period*/

This would be read as
data new;
set library.casesold;

If the character following a macro variable is a period, then you need to use two periods.
set in&nagasuchi..select;

After resolution, SAS would read this as SET incases.select;



More on this here.

Friday, June 15, 2007

LaTeX output in sas

/*Use one of the following ods statements */
/* Legacy LaTeX for ODS */
ods tagsets.latex file="legacy.tex";

/* Legacy LaTeX with color for ODS */
ods tagsets.colorlatex file="color.tex" stylesheet="sas.sty"(url="sas");

/* Simplified LaTeX output that uses plain LaTeX tables */
ods tagsets.simplelatex file="simple.tex" stylesheet="sas.sty"(url="sas");

/* Same as above, but only prints out tables (no titles, notes, etc.) */
/* Also, prints each table to a separate file */
ods tagsets.tablesonlylatex file="C:\Documents and Settings\mk\My Documents\tablesonly.tex" (notop nobot) newfile=table;

proc reg data=sashelp.class;
model Weight = Height Age;
run;quit;

/*Use one of the following ods statements corresponding to open statements*/

ods tagsets.latex close;
ods tagsets.colorlatex close;
ods tagsets.tablesonlylatex close;
ods tagsets.simplelatex close;

/*from SAS*/

Thursday, May 3, 2007

Unix Banner for interesting titles

ASCII Banner 1 , 2


  .'|.           .                                   '||  
.||. .... .||. .... .... .. ... .. ||
|| '' .|| || ||. ' '' .|| || || .' '||
|| .|' || || . '|.. .|' || || || |. ||
.||. '|..'|' '|.' |'..|' '|..'|' .||. ||. '|..'||.


||
.... .. ... ... . ... .. ... ....
'' .|| || || || || || || || '' .||
.|' || || || |'' || || || .|' ||
'|..'|' .||. ||. '||||. .||. .||. ||. '|..'|'
.|....'


  __       _                         _                     _            
/ _| __ _| |_ ___ __ _ _ __ __| | __ _ _ __ __ _(_)_ __ __ _
| |_ / _` | __/ __| / _` | '_ \ / _` | / _` | '_ \ / _` | | '_ \ / _` |
| _| (_| | |_\__ \ | (_| | | | | (_| | | (_| | | | | (_| | | | | | (_| |
|_| \__,_|\__|___/ \__,_|_| |_|\__,_| \__,_|_| |_|\__, |_|_| |_|\__,_|
Have fun. Don´t forget to bookmark this website :)


Thursday, April 19, 2007

Make results more presentable

SAS regression output requires additional steps to make it presentable. In previous posts, I have highlighted how to only get the results for variables of interest. However, these results are in row format

Obs F1 or lci uci p_value

1 exp1 1.202 1.110 1.34 .001
2 exp2 1.340 1.202 1.56 .001
3 exp3 1.560 1.340 1.89 .001
4 exp4 1.890 1.560 1.98 .001



This output need to be further transposed in Excel to get the results in following format.

Obs exp0 exp1 exp2 exp3 exp4

1 1 1.2020 1.3400 1.5600 1.8900
2 1.11,1.34 1.202,1.56 1.34,1.89 1.56,1.98
3 0.0010 0.0010 0.0010 0.0010


The following program eliminates that

proc import datafile="C:\Documents and Settings\mkaushik\Desktop\Output results.xls" out=auto replace;
run;
data inter /* / view=intermediate*/;
set auto;
orc= put(or,6.4);
pvaluec= put(p_value,6.4);
new=compress(lci||','||uci);
output; *output the input record;
if _n_=1 then do;
F1='exp0';
or=1; *set values for your added obs;
lci=.;uci=.;p_value=.;
orc="1";
pvaluec=" ";
new=" ";
output; *output your added obs;
end;
proc sort;
by F1;
run;
data inter;
set inter;
array Value (*) orc new pvaluec;
do id =1 to 3;
_value_ = value [id]; * since first numeric is that date;
F1=F1;
output;
end;
drop or p_value _name_;
run;
proc print data=inter;
run;

proc sort data=inter;
by id;
run;
proc transpose data=inter out=outset(drop=id _name_) ;
by id ;
id F1 ;
var _value_;
run;
proc print data=outset;
run;

Thursday, April 5, 2007

Correspondence between genmod and logistic

I have been exploring this for my work. I found some guidance here. I am including some details here.
data drug;
input drug$ x r n;
cards;
A .1 1 10
A .23 2 12
A .67 1 9
B .2 3 13
B .3 4 15
B .45 5 16
B .78 5 13
C .04 0 10
C .15 0 11
C .56 1 12
C .7 2 12
D .34 5 10
D .6 5 9
D .7 8 10
E .2 12 20
E .34 15 20
E .56 13 15
E .8 17 20
;

proc genmod data=drug;
class drug;
model r/n=x drug / dist=binomial link=logit;
estimate 'A vs E' drug 1 0 0 0 -1/exp;
run;

proc logistic data=drug;
class drug/param=ref;
model r/n=x drug;
run;


/* generates dummy variables coded as follows
drug A 1 0 0 0
B 0 1 0 0
C 0 0 1 0
D 0 0 0 1
E 0 0 0 0 */


proc logistic data=drug;
class drug;
model r/n=x drug;
run;


/* generates dummy variables coded as follows

Class Value Design Variables

drug A 1 0 0 0
B 0 1 0 0
C 0 0 1 0
D 0 0 0 1
E -1 -1 -1 -1
*/



However, the results (Odds ratio) are going to be the same. Accessible help on writing contrast statements is here.

Monday, April 2, 2007

Proc tabulate/proc report

I have been trying to learn these new tools.

Here is a pdf with clear instructions and uses of both.

Some available options are ACROSS, ANALYSIS, CENTER, COLOR, COMPUTED, CSS, CV, DESCENDING, DISPLAY, EXCLUSIVE, F, FLOW, FORMAT, GROUP, ID, ITEMHELP, LEFT, MAX, MEAN, MEDIAN, MIN, MISSING, N, NMISS, NOPRINT, NOZERO, ORDER, P1, P10, P25, P5, P50, P75, P90, P95, P99, PAGE, PCTN, PCTSUM, PRELOADFMT, PRT, Q1, Q3, QRANGE, RANGE, RIGHT, SPACING, STD, STDERR, STYLE, SUM, SUMWGT, T, USS, VAR, WEIGHT, WGT, WIDTH.