Good day:
i have this data:
data have;
input gender n;
cards;
male 7
female 3;
Gender | n |
Male | 7 |
Female | 3 |
What I need is to allocate all 10 individuals shown in the first table into a new one detailed as follows:
ID | Gender |
1 | Male |
2 | Female |
3 | Male |
4 | Male |
5 | Female |
6 | Male |
7 | Male |
8 | Female |
9 | Male |
10 | Male |
The rows can be allocated randomly, it is no need to be in the orther that im presenting it.
Thanks in advance
data want;
set have;
call streaminit(54);
do i=1 to n;
x= rand('normal');
output;
end;
run;
proc sort data=want out=want(drop=x);
by x;
run;
Something like above?
Depending on what proc you're using, you may also consider a WEIGHT or FREQ statement.
@jonatan_velarde wrote:
Good day:
i have this data:
data have;
input gender n;
cards;
male 7
female 3;
Gender n Male 7 Female 3
What I need is to allocate all 10 individuals shown in the first table into a new one detailed as follows:
ID Gender 1 Male 2 Female 3 Male 4 Male 5 Female 6 Male 7 Male 8 Female 9 Male 10 Male
The rows can be allocated randomly, it is no need to be in the orther that im presenting it.
Thanks in advance
How are we supposed to know that Id 1 is Male and not Female? Or any specific ID and Gender combination.
You are missing some details or data somewhere.
@jonatan_velarde wrote:
Thanks for the answer:
But is irrelevant if its male of female, this example is just for data simulation
Thanks again
I beg to differ. You have added a variable from somewhere. We need a rule.
If the spread of ID is not important then why did you go to the work of creating them that way.
It is trivial to get the males first and the females second:
data have;
input gender $ n;
do i=1 to n;
id+1;
output;
end;
drop i n;
cards;
male 7
female 3
;
You example strongly implied order had some importance. If not, then the above is one way.
data want;
set have;
call streaminit(54);
do i=1 to n;
x= rand('normal');
output;
end;
run;
proc sort data=want out=want(drop=x);
by x;
run;
Something like above?
Depending on what proc you're using, you may also consider a WEIGHT or FREQ statement.
@jonatan_velarde wrote:
Good day:
i have this data:
data have;
input gender n;
cards;
male 7
female 3;
Gender n Male 7 Female 3
What I need is to allocate all 10 individuals shown in the first table into a new one detailed as follows:
ID Gender 1 Male 2 Female 3 Male 4 Male 5 Female 6 Male 7 Male 8 Female 9 Male 10 Male
The rows can be allocated randomly, it is no need to be in the orther that im presenting it.
Thanks in advance
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.