DATA Step, Macro, Functions and more

Is it possible to get the data in ONE data step?

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 86
Accepted Solution

Is it possible to get the data in ONE data step?

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;

Accepted Solutions
Solution
‎06-15-2016 10:35 PM
Respected Advisor
Posts: 3,777

Re: Is it possible to get the data in ONE data step?

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


All Replies
Super User
Super User
Posts: 7,407

Re: Is it possible to get the data in ONE data step?

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;
Frequent Contributor
Posts: 86

Re: Is it possible to get the data in ONE data step?

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.

Frequent Contributor
Posts: 86

Re: Is it possible to get the data in ONE data step?

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

Solution
‎06-15-2016 10:35 PM
Respected Advisor
Posts: 3,777

Re: Is it possible to get the data in ONE data step?

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.

SAS Super FREQ
Posts: 3,482

Re: Is it possible to get the data in ONE data step?

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.

Frequent Contributor
Posts: 86

Re: Is it possible to get the data in ONE data step?

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

Respected Advisor
Posts: 3,777

Re: Is it possible to get the data in ONE data step?

[ Edited ]

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

 

What has STREAMINIT got to do with RANNOR? 

Frequent Contributor
Posts: 86

Re: Is it possible to get the data in ONE data step?

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.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

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