turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- Base SAS Programming
- /
- Is it possible to get the data in ONE data step?

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-15-2016 10:17 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Jack2012

06-15-2016 10:32 AM

```
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.

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Jack2012

06-15-2016 10:25 AM

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;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-15-2016 10:37 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-15-2016 10:39 PM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Jack2012

06-15-2016 10:32 AM

```
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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to data_null__

06-16-2016 12:26 PM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Rick_SAS

07-04-2016 05:46 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Jack2012

06-15-2016 10:34 AM - edited 06-15-2016 10:38 AM

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

What has STREAMINIT got to do with RANNOR?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to data_null__

06-15-2016 10:35 PM

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.