T-test in SAS datastep

The following SAS datastep conducts a test using functions in a datastep.

proc means data=both STACKODSOUTPUT n mean std min max stderr ;
class treat ;
var

<Variables here>

;
ods output summary=kaz2;
run;

data c;set kaz2;
if treat=0;
N_c=N;
mean_c=mean;
StdDev_c=StdDev;
Min_C=Min;
Max_C=Max;
StdErr_C=StdErr;
keep N_C MEAN_C StdDev_c MIN_C MAX_C StdErr_C Variable label;
run;

data t;set kaz2;
if treat=1;
N_t=N;
mean_t=mean;
StdDev_t=StdDev;
Min_t=Min;
Max_t=Max;
StdErr_t=StdErr;
Variable_QC=Variable;
keep N_T MEAN_T StdDev_t MIN_T MAX_T Variable_QC StdErr_t;
run;

data merge_CT;
merge C T ;
difference=MEAN_T-MEAN_C;

/*https://www.itl.nist.gov/div898/handbook/eda/section3/eda353.htm*/
POOLED_SE=sqrt( ( (StdDev_t*StdDev_t) / N_T ) + ( (StdDev_c*StdDev_c ) / N_C ) );

T_value=abs(difference)/POOLED_SE;

P_value=(1-probnorm(T_value))*2;
*if P_value < 0.1 then sig=”t”;
if P_value < 0.05 then sig=”* “;
if P_value < 0.01 then sig=”** “;
if P_value < 0.001 then sig=”***”;
if P_value =. then sig=””;

run;

SAS data merge problem

I have encountered a case where I am 100% sure the syntax is correct for merging datasets, but the result includes rows that are separate (while you expect them to see on the same row).  This is likely because string variables have different length of trailing blanks.  I recommend using STRIP function on IDs before the merge:

data lengthn;
input string $char8.;

kaz = strip(string);
datalines;
abcd
abcd
abcd
abcdefgh
x y z
;

proc print data=lengthn;
run;

This situation can occur easily, but it does not generate error messages.  This is a serious problem.

ORIGINAL REFERENCE:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a002295689.htm

How to copy names of files from a window’s folder

Imagine you have 100 excel files in your windows folder (or even 100,000) and you need to write names of those files in your SAS syntax (or any statistical software programs).  Typing 100 names is time consuming.  Instead you can use a cmd prompt at Windows and copy file names into a text file.

On Windows (7 in my case)

START –> RUN ..

Type in “cmd” in the pop-up window and OK it.

You get a small black window.  Type “cd” at the prompt to get  to the folder you want to go.

Examples:

  • cd Music  (You will go to a folder Music;but this folder has to exist in the folder you are currently in)
  • cd C:\temp (This will directly let you go to the folder you want to go regardless of where you are currently in the holder structure; I used an example of C:\temp)
  • cd .. (You go up one folder structure)

Once you get to the folder, you will do this (this is an example of getting text files that have extention “txt” e.g., abc.txt).

dir *.txt > example_of_cmd_text.txt

This will copy all files that end with extention “.txt” into a text file.  The resulting text file will include all file names in the folder.  This is an example:

http://www.nippondream.com/file/example_of_cmd_text.txt

It comes with additional pieces of information you may not need (e.g., date), so you want to open this with Excel and get exact information you need.

I googled for CMD commands tutorials: