01-19-2024
mmayorga
Fluorite | Level 6
Member since
10-25-2017
- 3 Posts
- 6 Likes Given
- 0 Solutions
- 1 Likes Received
-
Latest posts by mmayorga
Subject Views Posted 13987 08-30-2019 11:04 AM 14340 07-25-2019 11:02 AM -
Activity Feed for mmayorga
- Liked Re: Input date format like YYYY-MM-DD? for PaigeMiller. 03-25-2022 05:58 PM
- Liked Re: Input date format like YYYY-MM-DD? for PaigeMiller. 03-25-2022 05:58 PM
- Liked Re: Create a Macro Variable (REQUIRED) for Cynthia_sas. 08-09-2021 02:24 PM
- Liked Re: Assign sequential ID by multiple groups for tusher. 09-04-2020 01:53 PM
- Got a Like for Re: Multiple proc sorts. 01-18-2020 11:33 AM
- Posted Re: Multiple proc sorts on SAS Procedures. 08-30-2019 11:04 AM
- Posted Re: Multiple proc sorts on SAS Procedures. 07-25-2019 11:02 AM
- Liked Re: Proc Export - Error: String is duplicated for chazbash. 05-31-2018 03:51 PM
- Liked Re: How to assign a column value based on another column ?? for Steelers_In_DC. 10-25-2017 08:39 PM
-
Posts I Liked
Subject Likes Author Latest Post 1 2 5 1 1 -
My Liked Posts
Subject Likes Posted 1 07-25-2019 11:02 AM
08-30-2019
11:04 AM
I came up with another method. If you want to sort all the datasets in a library, then it does make sense to use PROC DATASETS before using CALL EXECUTE. Otherwise, you can list the datasets in a CARDS statement in the same DATA step as the CALL EXECUTE statement. data _null_;
input datasets $char50. ;
call execute
("proc sort data=work."||strip(datasets)||
"(keep=cum_freq cum_date rename=(cum_freq="||strip(datasets)||"))"||
"out="||strip(datasets)||";"||
"by ByVariable; run;");
cards;
dataset1
dataset2
dataset3
;run;
... View more
07-25-2019
11:02 AM
1 Like
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