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

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

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
/*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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
/*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;
PGStats
Opal | Level 21

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
PG
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
  • 2 replies
  • 1156 views
  • 3 likes
  • 3 in conversation