BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jack2012
Obsidian | Level 7

Dear All,

 

Not sure I should post this here or in IML. My question is quite simple: for the below code with 3 data steps I get data UV1, however could I reach the same target with ONLY ONE data step? I tried the Call Streaminit, but it seems I can't reach my expectation. Please help me if you can. Appreciated!!!


%let n_patient=25;/*Half NUmber of subjects enrolled*/
%let loop=20;/*Total number of loops conducted in the simulation*/
/***First Group***/
%let sigma1=1.5;/*Patient group sigma*/
%let sigma0=1;/*Healthy group sigma*/
%let mu1=1;   /*Patient group mean of measurements*/
%let mu0=0;   /*Healthy group mean of measurements*/
/***2nd Group***/
%let sigma1_=1.5;/*Patient group sigma*/
%let sigma0_=1;/*Healthy group sigma*/
%let mu1_=1;   /*Patient group mean of measurements*/
%let mu0_=0;   /*Healthy group mean of measurements*/
/***END***/

/***Sample 1 theory values***/
%let AUC_Theory=%sysfunc(round(%sysfunc(probnorm(%sysevalf((&mu1.-&mu0.)/%sysfunc(sqrt(%sysevalf(&sigma1.**2+&sigma0.**2)))))),0.00001));

/***Sample 2 theory values;***/
%let AUC_Theory_=%sysfunc(round(%sysfunc(probnorm(%sysevalf((&mu1_.-&mu0_.)/%sysfunc(sqrt(%sysevalf(&sigma1_.**2+&sigma0_.**2)))))),0.00001));

%put &AUC_Theory;
%put AUC_Theory=&AUC_Theory.
     sigma1=&sigma1.;


***%let cor=10;/*Number of correlation coefficients used; Correlation coefficient =rho/10*/


data UV0;
	do sampleID=1 to &loop.;
      do i=1 to &n_patient.;
                   seed=2**sampleID;
				   U=rannor(seed);
				   V=rannor(seed);
			       goldstandard_P=1;
				   goldstandard_H=0;
				   output;
		  end;
		end;
run;
/*Used to calculate Sample 1;**/
data UV0_1;
	set UV0;
    do rho=0,1;
	    output;
	end;
run;


/*Calculate the measurement for sample 1;*/

data UV1(keep=sampleID rho i U V SBJ1N_P SBJ1N_H goldstandard_P goldstandard_H);
    set UV0_1;
		sigma1=&sigma1.;
		sigma0=&sigma0.;
		mu1=&mu1.;
		mu0=&mu0.;
		SBJ1N_P=sigma1*U+mu1;
		SBJ1N_H=sigma0*((rho/10)*U+sqrt(1-(rho/10)**2)*V)+mu0;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19
data xUV1(keep=sampleID rho i U V SBJ1N_P SBJ1N_H goldstandard_P goldstandard_H);
   do sampleID=1 to &loop.;
      do i=1 to &n_patient.;
         seed=2**sampleID;
         U=rannor(seed);
         V=rannor(seed);
         goldstandard_P=1;
         goldstandard_H=0;
         do rho=0,1;
      		sigma1=&sigma1.;
      		sigma0=&sigma0.;
      		mu1=&mu1.;
      		mu0=&mu0.;
      		SBJ1N_P=sigma1*U+mu1;
      		SBJ1N_H=sigma0*((rho/10)*U+sqrt(1-(rho/10)**2)*V)+mu0;
            output;
            end;
         end;
      end;
   run;

It tested by running PROC COMPARE against your UV1.

View solution in original post

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Cant test at the moment, but I seen no reason you can't just move the code into one datastep?

data UV0;
  do sampleID=1 to &loop.;
    do i=1 to &n_patient.;
      do rho=0,1;
        seed=2**sampleID;
        U=rannor(seed);
        V=rannor(seed);
        goldstandard_P=1;
        goldstandard_H=0;
        sigma1=&sigma1.;
	sigma0=&sigma0.;
	mu1=&mu1.;
	mu0=&mu0.;
	SBJ1N_P=sigma1*U+mu1;
	SBJ1N_H=sigma0*((rho/10)*U+sqrt(1-(rho/10)**2)*V)+mu0;
        output;
      end;
    end;
  end;
run;
Jack2012
Obsidian | Level 7

This is the original code I used. And this is not what I wanted to see.

Anyhow you have changed the code and meet my expectation.

 

Many thanks again for your quick response.

 

Jack.

Jack2012
Obsidian | Level 7

The difficulty I faced is the vagueness of the control of the corder of the "Do rho=0 to 10" statement order coompare with with the do i=.. statement order.

 

Jack

data_null__
Jade | Level 19
data xUV1(keep=sampleID rho i U V SBJ1N_P SBJ1N_H goldstandard_P goldstandard_H);
   do sampleID=1 to &loop.;
      do i=1 to &n_patient.;
         seed=2**sampleID;
         U=rannor(seed);
         V=rannor(seed);
         goldstandard_P=1;
         goldstandard_H=0;
         do rho=0,1;
      		sigma1=&sigma1.;
      		sigma0=&sigma0.;
      		mu1=&mu1.;
      		mu0=&mu0.;
      		SBJ1N_P=sigma1*U+mu1;
      		SBJ1N_H=sigma0*((rho/10)*U+sqrt(1-(rho/10)**2)*V)+mu0;
            output;
            end;
         end;
      end;
   run;

It tested by running PROC COMPARE against your UV1.

Rick_SAS
SAS Super FREQ

I'm lat to this discussion, but just wanted to point ouf that the statement

         seed=2**sampleID;

doesn't do what you think it does. You might as well use

        seed=2;

which is equivalent, since the first call to RANNOR sets the seed to be 2 and all subsequent seeds are ignored.

Jack2012
Obsidian | Level 7

Really? I am not aware of this. The intention is to generate different for each sampleID and I can reproduce this in the future. I will take a look at it more closely with your notification and adivce. Many thanks.

 

Jack

data_null__
Jade | Level 19

Do you mean you want to move PROBNORM calls into the data step

 

What has STREAMINIT got to do with RANNOR? 

Jack2012
Obsidian | Level 7

Many thanks for your swift action. Call streaminit is used when the randomoization number is generated by the RAND function.

 

It does has no relationship with RANNOR function.

 

I think you have produced the right results in your previous post.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 1052 views
  • 2 likes
  • 4 in conversation