```Date: Thu, 11 Dec 1997 12:50:17 -0500 Reply-To: "Kevin F. Spratt" Sender: "SAS(r) Discussion" Comments: To: McGyver From: "Kevin F. Spratt" Subject: Re: Bivariate Normal Random Sample? In-Reply-To: <199712102353.RAA45912@moon.uiowa.edu> Content-Type: text/plain; charset="us-ascii" At 08:25 PM 12/10/97 GMT, McGyver wrote: >Can we draw a random sample from the bivariate normal distribution by >using SAS? If so, what's the commands for that. Thanks. > > >-- > > The program that follows illustrated how to create two normal distributions and how to create them so that they have the exact intercorrleation that you want. DM 'LOG;CLEAR;OUT;CLEAR;'; /* CLEARING LOG AND OUTPUT WINDOWS */ %PUT &SYSDATE &SYSTIME; /* PUT DATE & TIME AT TOP OF LOG */ /*******************************************************************/; /* */; /* */; /* SSSSSSS DDDDDD TTTTTTTTT CCCCCC */; /* SSSSSSSS DDDDDDDD TTTTTTTTT CCCCCCCC */; /* SS DD DD TTT CC */; /* SSSSSSSS DD DD TTT CC */; /* SS DD DD TTT CC */; /* SSSSSSSS DDDDDDDD TTT CCCCCCCC */; /* SSSSSSS DDDDDDD TTT CCCCCC */; /* */; /* */; /* FOR: SPINE DIAGNOSTIC & TREATMENT CENTER */; /* */; /*******************************************************************/; /* */; /* PROJECT: CREATING RANDOM VARIABLES OF KNOWN INTERCORRELATION */; /* */; /*******************************************************************/; /* */; /* PURPOSE: CREATE DATA, AND VARIABLES OF KNOW INTERCORRELATION */; /* */; /* TITLE: D:\SASPGM\CORREL\PGM\CORR1.PGM */; /* */; /* DATE: 10/28/96 */; /* */; /*******************************************************************/; LIBNAME SAVE 'D:\SASPGM\CORREL\DAT'; LIBNAME LIBRARY 'D:\SASPGM\CORREL\FOR'; FILENAME LOG 'D:\SASPGM\CORREL\LOG\CORR1.LOG'; FILENAME OUT 'D:\SASPGM\CORREL\OUT\CORR1.O01'; FILENAME PGM 'D:\SASPGM\CORREL\PGM\CORR1.PGM'; DM 'PGM;RECALL;FILE PGM REP;'; /* SAVING PROGRAM AS RUN */ OPTIONS LS=130 PS=85 PAGENO=1; **************************************************************************; DATA WORK.ONE; /* CREATE DATA SET OF 1000 SUBJECTS */ DO I=1 TO 1000; ID=I;OUTPUT; END; RUN; DATA WORK.ONE;SET WORK.ONE; /* ASSOCIATE RANDOM NORMAL VARIABLES X AND Y WITH THE 1000 SUBJECTS */ X=RANNOR(12345);Y=RANNOR(23456); RUN; TITLE 'SHOWING CORRELATION BETWEEN THE TWO DISTRIBUTIONS'; PROC CORR DATA=WORK.ONE; VAR X Y; RUN; PROC PRINCOMP DATA=WORK.ONE OUT=WORK.TWO STANDARD; VAR X Y; PROC PRINT DATA=WORK.TWO; RUN; TITLE 'CREATING NEW DISTRIBUTIONS WITH EXACT CORRELATION WITH THE PRINCIPLE COMPONENT OF X1 (PRIN1)'; DATA WORK.TWO;SET WORK.TWO; PRIN10 =PRIN1*.1 + PRIN2*SQRT(1-.1**2); PRIN20 =PRIN1*.2 + PRIN2*SQRT(1-.2**2); PRIN30 =PRIN1*.3 + PRIN2*SQRT(1-.3**2); PRIN40 =PRIN1*.4 + PRIN2*SQRT(1-.4**2); PRIN50 =PRIN1*.5 + PRIN2*SQRT(1-.5**2); PRIN60 =PRIN1*.6 + PRIN2*SQRT(1-.6**2); PRIN70 =PRIN1*.7 + PRIN2*SQRT(1-.7**2); PRIN80 =PRIN1*.8 + PRIN2*SQRT(1-.8**2); PRIN90 =PRIN1*.9 + PRIN2*SQRT(1-.9**2); PRIN95 =PRIN1*.95 + PRIN2*SQRT(1-.95**2); PRIN99 =PRIN1*.99 + PRIN2*SQRT(1-.99**2); PRIN999=PRIN1*.999 + PRIN2*SQRT(1-.999**2); RUN; PROC CORR DATA=WORK.TWO; VAR PRIN1; WITH PRIN2 PRIN10 PRIN20 PRIN30 PRIN40 PRIN50 PRIN60 PRIN70 PRIN80 PRIN90 PRIN95 PRIN99 PRIN999; RUN; **************************************************************************** ************************; DM 'LOG;FILE LOG REP;OUTPUT;FILE OUT REP;'; /* SAVING LOG AND OUTPUT SCREENS */ ___________________________________________________________ Kevin F. Spratt Iowa Testing Programs & Spine Diagnostic & Treatment Center 224-D Lindquist Center University of Iowa Iowa City, Iowa 52242 (319) 335-5572 (voice) (319) 335-6399 (fax) Kevin-Spratt@Uiowa.edu (e-mail) ```

Back to: Top of message | Previous page | Main SAS-L page