简体   繁体   中英

If/Then statement in SAS

thanks for taking time to help me out.

Basically, I would like to generate a random number from 0 to 1, 15,000 times and if the generated value is below .25, then I would like it to display 0 in that spot in the table. If it is greater than .25, I would like to keep the original value.

Any tips on what I should use in the asterik part? The code is pasted below in the format I used:

data rand_data;
call streaminit(123);

do i = 1 to 15000;
    u = rand('Uniform');
   ***if u < .25 then do;
    0 
   else*** 
   output;
   end;
   run; 
proc print data= rand_data;
run;

It sounds like you want to replace values that are less than 0.25 with 0.

if u < 0.25 then u=0;
output;

If instead you want to ignore the values that are less than 0.25 then make the OUTPUT statement conditional.

if u >= 0.25 then output;

Given your code structure this could result in less than 15,000 observations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM