Showing posts with label SAS. Show all posts
Showing posts with label SAS. Show all posts

Friday, December 5, 2008

Meta data Creation

Meta data creation in clinical trials comes handy to see what kind of variables are currently in a dataset and its attributes with format name and its decodes.

It should be a straight forward code using the procedures proc contents and proc format with few data steps.

proc contents data=libname.dsname out=contents(keep=memname name type fmtname length label rename=(format=fmtname));
run;

proc format fmlib cntlout=formats(keep=format start label rename=(label=label1));
run;

Merge datasets you have got by fmtname. Include a dummy variable comment to write later on it if you have any specific comments about the same.

data metadata;
merge contents formats;
by fmtname;
comment="";
run;

proc print noobs label;
run;

Monday, May 12, 2008

AE Summary Tables by SOC

Adverse Events Summary is one of the important tables generated in clincal trials industry.

Let us see how we could construct an AE table..

Important Points to remember:
1. AE Verbatim terms are to be coded with standard medical dictionaries, MeDRa.
2.SOC Name and Pt name are important variables that would be used for developing table.
3.Each Patient or Unique Patient Id is Counted only once for each of the SOC term and once for the Pt Name in each SOC term.

Code:

proc sort data=ae out=ae1;
by rand site ptid socname;
run;

proc sort data=ae out=ae2;
by rand site ptid socname ptname;
run;


proc freq data=ae1;
tables socname/out=ae1;
by rand;
run;

proc freq data=ae2;
tables socname*ptname/out=ae2;
by rand;
run;

Now set the datasets ae1 (with counts for soc term) and ae2 (with the counts for soc term *pt term) by soc term.

you would have the counts in each of the trt group(rand) for the soc term and pt term. Transpose the datasets or set accordingly to result in the counts for each of the trt group. Percents are calculated by using denominator N from the number of Patients enrolled(Like Demographics Dataset for ITT) and N from the number of Patients intended to treat from Randomization dataset for the safety analysis.

Friday, January 11, 2008

Detecting Outliers based on 99% quantiles

libname raw "PATH";

ods output Quantiles=quantiles;
proc univariate data=raw.clinic;
var height;
run;
ods output close;

data quantiles;
set quantiles;
where Quantile="99%";
run;


data final(drop=varname estimate);
retain estimate _estimate;
set quantiles raw.clinics;
if _n_=1 then _estimate=estimate;
if _n_=1 then delete;
if _estimate>height then output;
run;













































































run;

Wednesday, January 9, 2008

THIS VARIABLE IS UNINITIALIZED

THIS VARIABLE IS UNINITIALIZED


Sometimes when one is coding a specified data set structure,
some of the variables will be uninitialized. This results in the SAS Log message similar to:

NOTE: Variable z is uninitialized.

This is not acceptable if one is a member of the “Clean SAS Log”
club.

data … ;
attrib

;
%* prevent NOTE: Variable ***** is uninitialized.
messages ;
retain _character_ ‘’ _numeric_ . ;
stop ;
run ;


Richard supplied the following caution for his trick: “Only use this
with impunity when creating a zero rowed table of desired structure
as set forth in prior attrib statements(s).”

Source:http://www.bassettconsulting.com/CC014.pdf

SAS Functions (an excerpt)

SAS FUNCTIONS
Arithmetic Functions
ABS(argument)
returns absolute value
DIM(array-name)
returns the number of elements in a one-dimensional array or the number of elements in a specified dimension of a multidimensional array.
n specifies the dimension, in a multidimensional array, for which you want to know the the number of elements.
DIM(array-name,bound-n)
returns the number of elements in a one-dimensional array or the number of elements in the specified dimension of a multidimensional array
bound-n specifies the dimension in a multidimensional array, for which you want to know the number of elements.
HBOUND(array-name)
returns the upper bound of an array
HBOUND(array-name,bound-n)
returns the upper bound of an array
LBOUND(array-name)
returns the lower bound of an array
LBOUND(array-name,bound-n)
returns the lower bound of an array
MAX(argument,argument, ...)
returns the largest value of the numeric arguments
MIN(argument,argument, ...)
returns the smallest value of the numeric arguments
MOD(argument-1, argument-2)
returns the remainder
SIGN(argument)
returns the sign of a value or 0
SQRT(argument)
returns the square root

Character Functions
BYTE(n)
returns one character in the ASCII or EBCDIC collating sequence where nis an integer representing a specific ASCII or EBCDIC character
COLLATE(start-position<,end-position>) (start-position<,,length>)
returns an ASCII or EBCDIC collating sequence character string
COMPBL(source)
removes multiple blanks between words in a character string
COMPRESS(source<,characters-to-remove>)
removes specific characters from a character string
DEQUOTE(argument)
removes quotation marks from a character value
INDEX(source,excerpt)
searches the source for the character string specified by the excerpt
INDEXC(source,excerpt-1<, ... excerpt-n>)
searches the source for any character present in the excerpt
INDEXW(source,excerpt)
searches the source for a specified pattern as a word
LEFT(argument)
left-aligns a SAS character string
LENGTH(argument)
returns the length of an argument
LOWCASE(argument)
converts all letters in an argument to lowercase
QUOTE(argument)
adds double quotation marks to a character value
RANK(x)
returns the position of a character in the ASCII or EBCDIC collating sequence
REPEAT(argument,n)
repeats a character expression
REVERSE(argument)
reverses a character expression
RIGHT(argument)
right-aligns a character expression
SCAN(argument,n<,delimiters>)
returns a given word from a character expression
SOUNDEX(argument)
encodes a string to facilitate searching
SUBSTR(argument,position<,n>)=characters-to-replace
replaces character value contents
var=SUBSTR(argument,position<,n>)
extracts a substring from an argument. (var is any valid SAS variable name.)
TRANSLATE(source,to-1,from-1<,...to-n,from-n>)
replaces specific characters in a character expression
TRANWRD(source,target,replacement)
replaces or removes all occurrences of a word in a character string
TRIM(argument)
removes trailing blanks from character expression and returns one blank if the expression is missing
TRIMN(argument)
removes trailing blanks from character expressions and returns a null string if the expression is missing
UPCASE(argument)
converts all letters in an argument to uppercase
VERIFY(source,excerpt-1<,...excerpt-n)
returns the position of the first character unique to an expression

Date and Time Functions
DATDIF(sdate,edate,basis)
returns the number of days between two dates
DATE()
returns the current date as a SAS date value
DATEJUL(julian-date)
converts a Julian date to a SAS date value
DATEPART(datetime)
extracts the date from a SAS datetime value
DATETIME()
returns the current date and time of day
DAY(date)
returns the day of the month from a SAS date value
DHMS(date,hour,minute,second)
returns a SAS datetime value from date, hour, minute, and second
HMS(hour,minute,second)
returns a SAS time value from hour, minute, and second
HOUR(

ODS ExcelXp tagsets usage.

The following program will gnerate an output in nicely formatted excel spread sheet.

Please change the file path, sheet name, style and dataset name for your purpose.


ods TAGSETS.EXCELXP file="test.xls"
style=default

options (orientation="Landscape"
AUTOFILTER='1'
FROZEN_HEADER='YES'
FROZEN_ROWHEADER='YES');
ODS TAGSETS.EXCELXP OPTIONS (sheet_name='Sheet_1');
proc print data=d1;
run;
ODS TAGSETS.EXCELXP OPTIONS (sheet_name='Sheet_2');
proc print data=d2;
run;
ods tagsets.excelxp close;

Missing Values in SAS


Missing values in SAS
Numeric missing values are represented by a single period (.).
Character missing values are represented by a single blank enclosed in quotes (' ').
Special numeric missing values are represented by a single period followed by a single letter or an underscore (for example .A, .S, .Z, ._).
Special missing values
These are only available for numeric variables and are used for distinguishing between different types of missing values.
Responses to a questionnaire, for example, could be missing for one of several reasons (Refused, illness, Dead, not home). By using special missing values, each of these can be tabulated separately, but the variables are still treated as missing by SAS in data analysis.data survey;
missing A I R;
input id q1;
cards;
8401 2
8402 A
8403 1
8404 1
8405 2
8406 3
8407 A
8408 1
8408 R
8410 2
;
proc format;
value q1f
.A='Not home'
.R='Refused'
;
run;
proc freq data=survey;
table q1 / missprint;
format q1 q1f.;
run;
Sort order for missing values
There is a serious logic error in the following code:if age < 20 then agecat=1;
else if age < 50 then agecat=2;
else if age ge 50 then agecat=3;
else if age=. then agecat=9;
Sort order
Symbol
Description
smallest
_
underscore

.
period

A-Z
special missing values A (smallest) through Z (largest)

-n
negative numbers

0
zero
largest
+n
positive numbers
Working with missing values
When transforming or creating SAS variables, the first part of the code should deal with the case where variables are missing.if age=. then agecat=.;
else if age < 20 then agecat=1;
else if age < 50 then agecat=2;
else agecat=3;
Note that if you use special missing values then 'if age=.' cannot be used and 'if age le .Z' must be used to identify missing values.
Note that the result of any operation on missing values will return a missing value. In the following example, the variable total will be missing if any one of q1-q6 is missing.total=q1+q2+q3+q4+q5+q6;
An alternative is to use:total=sum(of q1-q6);
in which missing values are assumed to be zero.
Even if you think that a variable should not contain any missing values, you should always write your code under the assumption that there may be missing values.