Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sequential number generation

Status
Not open for further replies.

nirmalraj

MIS
Apr 20, 2005
33
US
Hi,
Is there a method for generating sequential numbers
000001
000002
000003
.
.
.
.
.

Since I did not know any specific method, I used excel and then saved it in formatted space delimited text and read the file to create a sequential dataset.
I also want to combine this sequential dataset with 1 other dataset and concatenate this value with 2 other variables.
" x1||seq_num||a1"

The issue that I face is it gives me a blank in the seq_num position which is true as it is a different dataset.Does anyone know the solution for this.

I want a result in this form

ab123456cd where ab and cd are from same dataset and 123456 is from sequential dataset.I have to create around 2000 total observations.
aa000001bb
cc000002dd
ee000003ff
.
.
.
.

Thanks

Raj
 
either
Code:
  sequence = _n_;
which works if you are writing out every single record, or
Code:
  retain sequence 0;
  sequence + 1;
which will increment each time the command is run, allowing you to be a bit more selective. Should sort you out. You can also use a Do Loop and an output statement to build your dataset, but that doesn't sound like what you want to do.
 
Thanks Chris,

It did work out good but my field length is 6 thats it should start with 000001 instead of 1. is there any possible way by which this could be done.

Thanks
Raj
 
This'll do it.
Code:
  length seq_char $6;
  seq_char = put(sequence,z6.);
 
thats correct but i think we should use

Code:
length seq_char 6.;

seq_char = put(sequence,z6.);

to retain as numeric and fill in leading zero's.I need not keep '$'.

 
If you want to keep the field as a numeric then skip all that and just put this in the datastep
Code:
  format sequence z6.;
Leading zeroes won't be retained in a numeric field, it is a pure formatting issue.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top