BookmarkSubscribeRSS Feed
thanikondharish
Fluorite | Level 6

data main ;
input subid $ condition $ ;
cards ;
101 normal
101 abnormal
102 normal
102 abnormal
103 normal
103 abnormal
;

how to assign type variable

i want to data like see below 

subid

condition

type

101

normal

0

101

abnormal

1

102

normal

1

102

abnormal

0

103

normal

0

103

abnormal

1

10 REPLIES 10
PaigeMiller
Diamond | Level 26

Please explain the process that assigns a 0 or 1 to type.

--
Paige Miller
thanikondharish
Fluorite | Level 6
subjects have type numbers like 0 means subject is not in that condition ,
1 means subject present in that condition
PaigeMiller
Diamond | Level 26

@thanikondharish wrote:
subjects have type numbers like 0 means subject is not in that condition ,
1 means subject present in that condition

But this explains nothing. The question is not what does 0 or 1 mean. The question is: How do we assign the 0 or the 1?

--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

Please post full information, how is the 0 or 1 assigned?  Maybe:

x=rand('UNIFORM');

From the manual:

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a001466748.htm

PeterClemmensen
Tourmaline | Level 20

Is type simply a random 0/1 variable?

 

If so then do

 

data want;
   set main;
   a=rand('Integer', 0, 1);
run;
VDD
Ammonite | Level 13 VDD
Ammonite | Level 13

is 0 and 1 always assigned to normal = 0 and abnormal = 1?

 

having a full understanding of what you have and what you want, and maybe the why helps others understand without having to solve the implied assumptions.

 

 

PaigeMiller
Diamond | Level 26

@VDD wrote:

is 0 and 1 always assigned to normal = 0 and abnormal = 1?

 


The original example did not follow this rule.

 

having a full understanding of what you have and what you want, and maybe the why helps others understand without having to solve the implied assumptions.

 

Yes, I agree completely, there's no way to answer the question without this explanation.

--
Paige Miller
ballardw
Super User

One way to assign a random value of 0 or 1.

data want;
 set have;
 type= rand('table',.5, .5) -1;
run;

The .5 are the probabilities of selection. If you want/need other than 50/50 split adjust the values but keep a total of 1.

 

Reeza
Super User

RAND() function with Bernoulli option and you can specify the probability of a 0 or 1. 

 


@thanikondharish wrote:

data main ;
input subid $ condition $ ;
cards ;
101 normal
101 abnormal
102 normal
102 abnormal
103 normal
103 abnormal
;

how to assign type variable

i want to data like see below 

subid

condition

type

101

normal

0

101

abnormal

1

102

normal

1

102

abnormal

0

103

normal

0

103

abnormal

1


 

Ksharp
Super User
data main ;
input subid $ condition $ ;
array x{0:1} _temporary_ ;
call streaminit(12345678);
i=mod(_n_,2);
if i=1 then do;
    if rand('bern',0.5)=1 then do;x{0}=1;x{1}=0;end;
	 else do;x{0}=0;x{1}=1;end;
end;
flag=x{i};
drop i ;
cards ;
101 normal
101 abnormal
102 normal
102 abnormal
103 normal
103 abnormal
;

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 10 replies
  • 1959 views
  • 0 likes
  • 8 in conversation