BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
jonatan_velarde
Lapis Lazuli | Level 10

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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
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


 

View solution in original post

4 REPLIES 4
ballardw
Super User

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
Lapis Lazuli | Level 10
Thanks for the answer:

But is irrelevant if its male of female, this example is just for data simulation

Thanks again
ballardw
Super User

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

Reeza
Super User
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


 

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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