BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
tbanh
Fluorite | Level 6

Hi all,

 

I have a dataset with 5472 observations but I would like to split it up into two datasets with 2736 observations each. I would like to do this by keeping the first 12 observations for the first dataset and the second 12 for the second, third 12 for the first, fourth 12 for the second, and so on. Is there a succinct way to do this? I am aware of the mod function but that only returns every nth value. Any help is appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User
Double MOD function?
retain group class;
if mod(_n_, 12) = 1 then group+1;
class = mod(group, 2);

You can probably combine those as well.

View solution in original post

6 REPLIES 6
Reeza
Super User
Double MOD function?
retain group class;
if mod(_n_, 12) = 1 then group+1;
class = mod(group, 2);

You can probably combine those as well.
novinosrin
Tourmaline | Level 20

@tbanh Please go with squeaky clean @Reeza 's solution, here is some fun to play with 🙂

 

data have;
do i=1 to 5472;
output;
end;
run;

data one two;
do _iorc_=1 to 2;
do _n_=1 to 12 until(lr);
set have end=lr;
if _iorc_=1 then output one;
else output two;
end;
end;
run;
Astounding
PROC Star

I'm not sure this is elegant, but it works:

 

data want1 want2;

do _n_=1 to 12;

   link retrieve;

   output want1;

end;

do _n_=1 to 12;

   link retrieve;

   output want2;

end;

return;

retrieve:  set have;

return;

run;

 

By using the same SET statement, both loops continue reading the next observation, then the next, etc.

Reeza
Super User

12 makes me think it's monthly data, is there perhaps another variable that would identify the groups? If so, there are ways to make this entirely data driven. 

tbanh
Fluorite | Level 6

Hi Reeza,

 

No it is not monthly data. I had PROC MCMC output simulated data from the posterior distribution for predicted values. Each individual (N = 228) had observations representing a quantitative task and a verbal task, thus my wanting to separate each individual's observations into a quantitative dataset and a verbal dataset. Thank you for your help!

Reeza
Super User

@tbanh wrote:

Hi Reeza,

 

No it is not monthly data. I had PROC MCMC output simulated data from the posterior distribution for predicted values. Each individual (N = 228) had observations representing a quantitative task and a verbal task, thus my wanting to separate each individual's observations into a quantitative dataset and a verbal dataset. Thank you for your help!


Do you have a variable that indicates if it's qualitative or quantitative? Trusting an implied order is a risky game.

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
  • 6 replies
  • 1074 views
  • 6 likes
  • 4 in conversation