I created a UID in my data set like so:
data two; set one; UID + 1; run;
the last record is:
name UID
Tom 899
I have a new data set named new_students like so:
name
**bleep**
Harry
etc.
I want to add these records to data set two to get this result:
name UID
Tom 899
**bleep** 900
Harry 901
etc
/*Existing sample with uid*/
data one;
set sashelp.class;
uid+1;
run;
/*Read the last uid and store in a macro var*/
data _null_;
set one nobs=nobs point=nobs;
call symputx('uid',uid,'g');
stop;
run;
/*write to the log to check the value to help debug if any*/
%put &=uid;
/*Increment the counter for two using uid macro var*/
data two;
set sashelp.class;
retain uid &uid;
uid+1;
run;
/*append two to one*/
proc append base=one data=two;
run;
/*Existing sample with uid*/
data one;
set sashelp.class;
uid+1;
run;
/*Read the last uid and store in a macro var*/
data _null_;
set one nobs=nobs point=nobs;
call symputx('uid',uid,'g');
stop;
run;
/*write to the log to check the value to help debug if any*/
%put &=uid;
/*Increment the counter for two using uid macro var*/
data two;
set sashelp.class;
retain uid &uid;
uid+1;
run;
/*append two to one*/
proc append base=one data=two;
run;
If you don't mind using undocumented SAS features:
data oldData;
do name = "Georges", "Henry", "Paul";
UID + 1;
output;
end;
run;
data newData;
do name = "Loretta", "Mary", "Suzy";
output;
end;
run;
proc sql;
select max(UID) into : maxUID from oldData;
insert into oldData (UID, name)
select &maxUID + monotonic(), name from newData;
quit;
proc print data=oldData; run;
Obs. name UID 1 Georges 1 2 Henry 2 3 Paul 3 4 Loretta 4 5 Mary 5 6 Suzy 6
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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 save with the early bird rate—just $795!
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.
Ready to level-up your skills? Choose your own adventure.