Hello, I am using the following code into a macro function to get the libname, memname, data type and the modate.
proc sql;
create table &nsource. as
select libname,
memname,
memtype,
modate
from sashelp.vtable
where libname="&lbname."
and &enddate.>= datepart(modate)>= &startdate.;
quit;
So I am getting a table gathering this information for each &nsource. Each table could contains about 30 observations.
When those table are created, I could use the libname and the memname as well as a proc sql as below to get the min and max value.
proc sql;
create table &nsource_memname as
select min(transaction_dt) as mintransacdate,
max(transaction_dt) as maxtransacdate,
from &nsource;
quit;
I wonder if there is a more efficient way to do that?
I might be tempted to try something along the lines of:
proc sql; select catx('.',libname,Memname) into :memlist separated by ' ' from sashelp.vtable where libname="&lbname." and memtype='DATA' and &enddate.>= datepart(modate)>= &startdate.; quit; data need; set &memlist. indsname=dsn; source=dsn; run; proc summary data=need nway; class source; var transaction_dt; output out=want (drop=_:) min(transaction_dt)=mintransacdate max(transaction_dt)=maxtransacdate ; run;
This creates one output data set with the source data set name as a variable.
Can we see the entire code?
How could this work anyway? There is no variable named transaction_dt in data set &nsource.
I might be tempted to try something along the lines of:
proc sql; select catx('.',libname,Memname) into :memlist separated by ' ' from sashelp.vtable where libname="&lbname." and memtype='DATA' and &enddate.>= datepart(modate)>= &startdate.; quit; data need; set &memlist. indsname=dsn; source=dsn; run; proc summary data=need nway; class source; var transaction_dt; output out=want (drop=_:) min(transaction_dt)=mintransacdate max(transaction_dt)=maxtransacdate ; run;
This creates one output data set with the source data set name as a variable.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.