SAS Notes

Compiled by : Wilson Suraweera @ CGHR
Contents
Random Numbers in SAS
Data Sub-setting
Selection  of  two Random Samples
Identification and Separation of duplicate records in SAS dataset
Reshape Long list variable dataset to Wide list dataset
Missing values replacement with Means of the respective Variables
Logistic Regression with SAS
SAS made easy using Proc SQL
SAS PROC SQL procedure to access external ODBC data sources
SAS String Data Handling
SAS Missing value arithmetic's
          Update_a_Table_using_Another_Table_in_SAS
Text analysis - an Epidemiological Case Study by WS - SAS Institute HUG -01 April2011
 
External Resources
SAS Knowledge Base - Glossary of SAS Procedures from SAS.com
SAS resources from - UCLA
Logistic regression
          Survival Analysis : Usage of Proc LifeTest and Proc PHREG
SAS Dinosaur - Old and New way of SAS programming
Paul Dicman's Web Page for SAS- This little old discusses SAS 8, but useful
Global Statements Dictionary - Alphabetical listing and Description of SAS Key words
SAS Study Blog
SAS Canada - User Groups
         

/* Copy these codes and make your own program */

These examples illustrate how to create a random sample or multiple samples in one shot from a large dataset

(1) Selection of a random sample from a dataset

 
	 data Sample;
                n=1;                  /* n=500 is sample sizes each*/
                DSize=122533;         /* DSize is number of records in the original data set involved in random sample: You can select your own  */
                  do while (n < 501);      
                        Slice=int(DSize*ranuni(-1));     
                        set mydataset point=Slice;        /* you have to replace mydataset with one of your existing dataset here*/
                         if ( (compress(Language) in ('2')) and (compress(Form) in ('42')) and (n<=500)) then do;
						          /* This is a some of my arguments imposed on selection: you can have your own.*/
                            output sample;
                               n=n+1;
                          end;
                  end;
                  stop;
             drop n;
          run; 
 
 

(2) Selection of 2 random samples from a dataset

            data Sample1 sample2;

                n1=0; n2=0;                 /* n1, n2 are smaple sizes Suppose we want to have 2 male and female samples of 100 each*/

                  do while ((n1+n2)< 200);     

                        Slice=int(69514*ranuni(-1));     /* This is # of observations in your data set */

                          set mydataset point=Slice;    /* u have to replace mydataset with one of your existing dataset here*/

                           if gender=1 and n1<=100) then do;

                            output sample1;

                                            n1=n1+1;

                                    end;

                                 else if (n2<=100) then  do;

                              output sample2;

                                           n2=n2+1;

                                end;

                  end;

                  stop;

             drop n1 n2;

             run;

Back to Top