-1

In SAS, I have a table that have 1000 rows. I am trying to separate that table into two tables. Row1-500 to Table A and row501-100 to table B. What is the code that can do this function. Thank you all for helping!

I am searching the code online and cannot get anything on google, help is appreciated.

Jason Qian
  • 11
  • 4
  • Please show what you've tried so far. https://blogs.sas.com/content/sgf/2020/07/23/splitting-a-data-set-into-smaller-data-sets/ – Reeza Feb 13 '23 at 18:08

2 Answers2

2

The DATA statement lists the output tables of the step. An OUTPUT statement explicitly sends a row to each of the output tables. An explicit OUTPUT <target> ... <target-k> statement sends records to the specified tables only. The automatic implicit loop index variable _n_ can act as a row counter when a single data set is being read with SET.

Try

data want1 want2;
  set have;
  if _n_ <= 500 then output want1; else output want2;
run;

However, you may be better served by creating a categorical variable that can be used later in WHERE or BY statements.

Richard
  • 25,390
  • 3
  • 25
  • 38
0

Maybe the set options will help.Try firstobs= and obs= to choose the rows you want. Here is how to use them:

data want1;
  set have(obs=500);
run;
data want2;
  set have(firstobs=501 obs=1000);
run;
freya
  • 36
  • 5