@kalbo Your descriptions are somewhat confusing. May be that's because of formulations like:
>CORE1 should be replaced by a list of variables That's not a list of variables. You want to replace records with specific values for variables dataset and variable with values from some other records in the same table. What increases the confusion are the variable names "variable" and "dataset".
>The ADSL records can be added to any data set in the list
What's confusing here: In the SAS world the term "data set" normally means "table" and not row/observation/record.
Based on your WANT data I believe what you're after is something like below:
data have;
infile cards dsd truncover;
input dataset $ variable : $10. label : $20. coregroup $;
cards;
ADAE,USUBJID,Subject_ID,
ADAE,:CORE1,,
ADAE,:CORE2,,
ADAE,TRT,Treatment,
ADMH,USUBJID,Subject_ID,
ADMH,MHTERM,Medical_History_Term,
ADMH,TRT,Treatment_Group,
ADSL,USUBJID,Subject_ID,
ADSL,RAND,Rand_flag,1,
ADSL,ETHNEW,New_Ethnicity,2,
ADSL,SITEID,Site_ID,1,
;
data want;
input dataset $ variable : $10. label : $20. coregroup $;
datalines;
ADAE USUBJID Subject_ID .
ADAE RAND Rand_flag 1
ADAE SITEID Site_ID 1
ADAE ETHNEW New_Ethnicity 2
ADAE TRT Treatment .
ADMH USUBJID Subject_ID .
ADMH MHTERM Medical_History_Term .
ADMH TRT Treatment_Group .
ADSL USUBJID Subject_ID .
ADSL RAND Rand_flag 1
ADSL ETHNEW New_Ethnicity 2
ADSL SITEID Site_ID 1
;
run;
data want_derived;
if _n_=1 then
do;
dcl hash h1(dataset:'have(where=(dataset="ADSL" and not missing(coregroup))', multidata:'y');
h1.defineKey('coregroup');
h1.defineData('variable','label','coregroup');
h1.defineDone();
end;
set have;
if dataset='ADAE' and find(variable,'core','i')>0 then
do;
do while(h1.do_over(key:strip(scan(variable,-1,,'kd'))) eq 0);
output;
end;
end;
else
output;
run;
proc compare data=want compare=want_derived;
run;
proc print data=want;run;
proc print data=want_derived;run;
... View more