If the ultimate goal is to merge multiple datasets, then you can do it using PROC SQL. The code below is an excerpt from "PROC SQL: Tips and Translations for Data Step Users" by Susan P Marcella & Gail Jorgensen, which you can find here: https://www.lexjansen.com/nesug/nesug10/hw/hw05.pdf Instead of this: proc sort data=L.drinkers; by id; run;
proc sort data=L.smokers; by id; run;
data L.LJSmokeDrinkdata;
merge L.smokers(in=smoke) L.drinkers(in=drink);
by id;
if smoke;
run; Use this: proc sql;
create table L.LJSmokeDrinkSQL as
select s.*, d.*
from L.smokers as s join L.drinkers as d
on s.id=d.id;
quit; Alternatively, you can use PROC DATASETS and the CALL EXECUTE statement within a DATA step to sort datasets. In the code below, I first create the dataset myMembers, which contains the variable NAME that gives me the names of all Datasets (memtype=data) on the WORK library. Then, CALL EXECUTE allows me to run the same code on all datasets that have the letter 't' in their name (specified by the WHERE statement). ods output Members=myMembers;
proc datasets lib=work memtype=data; run;
ods output close;
data _null_; set myMembers;
call execute ('proc sort data=work.'||strip(Name)||'; by Patient_ID; run;');
where find(name,'t','i');
run; I usually reserve CALL EXECUTE for instances where I have several lines of code to do on at least 5 datasets, or simple code on more than 10 datasets. Hope this helps! Good luck!
... View more