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

Hi all!

 

I would like to continue numbering from a fixed number. There is a table in one id eg: 101 . And there is another table where this id is not filled and I want to continue the numbering like a monotonic number in this field.

 

I hope I have made it clear example.

 

Thanks for all.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

@ger15xxhcker 

Below should work as well:

proc sql noprint;
  select max(id) into :max_id trimmed
  from table1
  ;
quit;

data table2_want;
  set table2;
  id=sum(&max_id,_n_);
run;

View solution in original post

5 REPLIES 5
PeterClemmensen
Tourmaline | Level 20

Just to get things started, lets assume your data looks like this

 

data Table1;
input id var;
datalines;
1 10
2 20
3 30
4 40
5 50
;

data Table2;
input id var;
datalines;
. 10
. 20
. 30
. 40
. 50
;

From what I understand, you want the Id values in Table2 to be filled with values 6, 7, 8, 9 and 10, correct?

PeterClemmensen
Tourmaline | Level 20

This approach does not require the data to be sorted

 

data Table1;
input id var;
datalines;
3 30
2 20
5 50
4 40
1 10
;

data Table2;
input id var;
datalines;
. 10
. 20
. 30
. 40
. 50
;

data want(drop=_:);
    do until (lr1);
        set Table1 end=lr1;
        if id gt _id then _id=id;
    end;
    do _N_=1 by 1 until (lr2);
        set Table2 end=lr2;
        id=_id+_N_;
        output;
    end;
run;
Patrick
Opal | Level 21

@ger15xxhcker 

Below should work as well:

proc sql noprint;
  select max(id) into :max_id trimmed
  from table1
  ;
quit;

data table2_want;
  set table2;
  id=sum(&max_id,_n_);
run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1641 views
  • 1 like
  • 3 in conversation