Derive AGE off Date of Birth in SAS

libname kaz "…"; data a; set kaz.Query; FORMAT fixed_date date9. ; fixed_date=mdy(10,20,2016);


keep age FINAL_DOB; run;

How to QC the result of random assignment

QC 1:

Check the number of cases within each group (i.e. treatment and control group).


Check if the number of treatment school and control school is balanced within block.



Counting how many times does a string occur in a variable


Creating Sequence Values per ID


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 […]

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 […]

SAS DATASETS to delete all files in work directory

proc datasets library = work kill nolist; quit;

How to delete datasets in SAS using PROC DATASETS

Deleting all temporary datasets:

proc datasets library = work kill nolist; quit;

Deleting specific datasets in the temp directory:

proc datasets; delete kaz1 estes diminfo concon FITSTAT hlm1; run;

How to check if a sas dataset was created or not

/*CHECK IF COVPARMS is CREATED*//*CHECK IF COVPARMS is CREATED*/ %macro checkds(dsn); %if %sysfunc(exist(&dsn)) %then %do; proc print data = &dsn;run; data HLM_OR_NOT;value="YES_HLM";run; %end; %else %do; data covparms;CovParm="NoCov";run; data HLM_OR_NOT;value="NO_HLM ";run; %end; %mend checkds; /* Invoke the macro, pass a non-existent data set name to test */ %checkds(work.covparms); data _null_;set hlm_or_not; call symput ("hlm_or_not",value); run; %put […]