Saturday, December 20, 2008

Capturing the data into a macro

-
For the display of (N=xx) in a summary table, we have to capture the data into a macro. There are two different methods for capturing the data into a macro. One is using PROC SQL & the other one is using CALL SYMPUT.
-
***** GETTING "N" FOR EACH TRT GROUP *****;
-
1) PROC SQL:
-
data total;
set main(where=(saf=1));
trtgrp = input(treat,best.);
output;
trtgrp = 3;
output;
run;
-
proc sql noprint;
select count(distinct usubjid) into : trt1 through : trt3 from total group by trtgrp;
quit;
%put &trt1 &trt2 &trt3;
-
2) SYMPUT:
-
proc freq data = total noprint;
tables trtgrp / out = deno(drop = percent) list missing;
run;
-
data _null_;
set deno;
if trtgrp=1 then call symput('trt1',trim(left(put(count,3.))));
if trtgrp=2 then call symput('trt2',trim(left(put(count,3.))));
if trtgrp=3 then call symput('trt3',trim(left(put(count,3.))));
run;
-

Thursday, December 18, 2008

DUPOUT=option

-
The following data set contains duplicate observations for Patients (PT:- 01 & 02) :
-
PT NO
01 12
01 3
01 56
02 2
02 12
03 12
-
How does the dupout option work on this data?????
-
proc sort data = test out = dedup
-------------------------dupout = dups nodupkey;
--by pt;
run;

It works in a similar manner to nodupkey. Here the "duplicates are detected by the nodupkey option" & are directed into an output dataset with DUPOUT!

The dedup is an output data set that contains only the original observations.
PT NO
01 12
02 2
03 12
-
Where as the dups is an output data set that contains all duplicate observations.
PT NO
01 3
01 56
02 12

-

Tuesday, December 16, 2008

Use of SUBSTR with INDEX function

-
The syntax for substr function is:
SUBSTR(string, starting position, <length>)
-
It is easy to determine the starting position or the length of the string (if it contains DATE).
-
For example:
day=substr(date,1,2);

but the same substr function is not applicable if the string contains NAME. The reason is that the length of each name varies from one observation to the other. Hence the use of delimiters (like: "." ",") can be used to locate the position within the string.
-
Below is an example for the use of substr with index function:
-
*** INDEX IS USED TO FIND WHERE TO BEGIN & END A SUBSTRING ***;
-
data fullname;
length fname lname $20;
set nameds;
fname= substr(name, 1, index(name, ',') - 1);
lname = trim(left(substr(name, index(name, ',') + 1)));
run;
-
Output:
name----------------------- fname---- lname
SOMA, SUNDARAM---- SOMA---- SUNDARAM
SHIVA, SHEKARAN---- SHIVA---- SHEKARAN

-