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

Hi, Can anybody tell me how to add a series number for every 70 subjects, for 14000 subjects.  For example

subject     series

00001          1

00002          1

00003          1

...

00071          2

00072          2

...

000141        3

..

 

 

13931         200

...

14000          200

 

Thanks! 

1 ACCEPTED SOLUTION

Accepted Solutions
mkeintz
PROC Star

If program minimization is the goal:

 

data want;
  set have;
  series=  ceil(_n_/70);
run;

This technique can also be used when reading (and keeping 100%) of raw data:

 

data want;
  infile 'c:\temp\mydatalines.txt';
  input a b c … ;
  series=ceil(_n_/70);
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------

View solution in original post

4 REPLIES 4
Tom
Super User Tom
Super User

Are you generating that data?

data want;
  do series=1 to 200;
    do _n_=1 to 70 ;
      subject_num+1;
      subject=put(subject_num,z5.);
      output;
    end;
  end;
run;

Or generating SERIES for an existing dataset.

You can either count them yourself by placing the SET/OUTPUT statements inside a DO loop.

data want;
  series+1;
  do _n_=1 to 70;
    set have ;
    output;
  end;
run;

or convert the observation counter.  So 1-70 is mapped to 1 and 71-140 is mapped to 2, etc.

data want;
  set have ;
  series = 1+int((_n_-1)/70);
run;

 

r_behata
Barite | Level 11
data have;
	do _n_=1 to 14000;
		subect=put(_n_,z5.); output;
	end;
run;


data want;
	set have;
	retain series 1;

	_iorc_=mod(_n_,70);

	if _iorc_ eq 0 then series +1;
	
run;
mkeintz
PROC Star

If program minimization is the goal:

 

data want;
  set have;
  series=  ceil(_n_/70);
run;

This technique can also be used when reading (and keeping 100%) of raw data:

 

data want;
  infile 'c:\temp\mydatalines.txt';
  input a b c … ;
  series=ceil(_n_/70);
run;
--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
HappySASUE
Quartz | Level 8

Thank you so much! Really helpful. 

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 4 replies
  • 1026 views
  • 1 like
  • 4 in conversation