data have;
length Teammate $50;
input Process $ Teammate $;
datalines
AAAA John
AAAA Charles
BBBB Samuel
run;
input_record
LN PROCESS TEAMMATE
1 AAAA
2 AAAA
3 BBBB
PROC SQL;
CREATE TABLE COMBINE AS
SELECT *
FROM HAVE A
LEFT JOIN INPUT_RECORD B
ON A.PROCESS = B.PROCESS
;QUIT
If I run this code process AAAA will be assigned to teammate John for both 1 and 2. Is there a way to assigned this randomly (John would get 1 and Charles would get 2). The reason for this is because the customer provided a spreadsheet similar to input_record in which multiple people can be assigned the same process.
use a merge instead of join
data have;
length Teammate $50;
input Process $ Teammate $;
datalines;
AAAA John
AAAA Charles
BBBB Samuel
;
run;
data
input_record;
input
LN PROCESS $ ;
datalines;
1 AAAA
2 AAAA
3 BBBB
;
data want;
merge have(in=a) input_record(in=b);
by process;
if a;
run;
that should solve this
Given the OP's description of the objective, this solution depends ENTIRELY on
In other words, can the OP trust his data providers to be that consistent? Having a blank teammate variable, which would ordinarily be a match-key, diminishes one's confidence in the data provider.
you are so right @mkeintz
A SQL Query would produce a Cartesian product ( 5 rows in the sample output, 2 rows each for the repeated values) , are you sure is that is what you intend ? .
If "John would get 1 and Charles would get 2" is the only criteria use a data step merge instead. Not sure what you meant by "Random" in the example.
data have1;
length Process Teammate $50;
input Process $ Teammate$;
datalines;
POC James
POC Sam
POC Jane
run;
data have2;
length Process Teammate $50 ;
input ln Process $ Teammate $ ;
datalines;
12 POC James
55 POC
60 POC
;run;
data merge1;
merge have1 have2;
if process = 'POC';
run;
OUTPUT
ln Process Teammate
12 POC James
55 POC
60 POC
How can I modify the code to randomly assign the teammate in a sequencr of
James, Sam Jane
ln Process Teammate
12 POC James
55 POC Sam
60 POC Jane
72 POC James
88 POC Sam
99 POC Jane
....etc
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.