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. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

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