BookmarkSubscribeRSS Feed
iressa1313
Calcite | Level 5

Hi I have used SAS to generate 3 different distributions

1. N~ (0,1) with variable X1.....X20

2. N~ (5,1) with variable Y1.....Y20

3. B(0.5)  "bernoulli" with variable U1......U20

 

Now I want to create a new distribution Q where 

QX, if U = 0 and Y, if U =1

How would I do this? Would I create a new dataset with all 3 variables?

Thanks for any help!

 

 

3 REPLIES 3
ballardw
Super User

@iressa1313 wrote:

Hi I have used SAS to generate 3 different distributions

1. N~ (0,1) with variable X1.....X20

2. N~ (5,1) with variable Y1.....Y20

3. B(0.5)  "bernoulli" with variable U1......U20

 

Now I want to create a new distribution Q where 

QX, if U = 0 and Y, if U =1

How would I do this? Would I create a new dataset with all 3 variables?

Thanks for any help!

 

 


Probably, or merge existing data sets.

When you say  X, if U = 0 and Y, if U =1 do you mean if U=0 and U=Y or something else? Be very explicit. Also there appears to be something missing after "If U=1 …"

Astounding
PROC Star

You'll need to describe the data sets you have a little more.  For example, in the X data set:

 

Do you have 20 observations, each with a value for the variable X?  (If so, is there a separate variable taking on values 1 through 20?)

 

Do you have 1 observation, with variables named x1 through x20?

 

Do you have many observations, each with variables named x1 through x20?

 

It can't be all that difficult to compute Q, but it's a whole lot easier to program it once instead of three times.  So describe the input a bit more.

FreelanceReinh
Jade | Level 19

Hi @iressa1313,

 

I would keep it simple and create a new dataset with all four variables:

 

data want;
call streaminit(27182818);
do _n_=1 to 20;
  x=rand('norm');     /* X ~ N(0,1)     */
  y=rand('norm',5);   /* Y ~ N(5,1)     */
  u=rand('bern',0.5); /* U ~ Bin(1,0.5) */
  q=ifn(u,y,x);       /* normal mixture */
  output;
end;
run;

Or is there something special about your existing "distribution datasets" that you don't want to discard them?

 

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and save with the early bird rate—just $795!

Register now

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 3 replies
  • 1363 views
  • 0 likes
  • 4 in conversation