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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Check out this tutorial series to learn how to build your own steps in SAS Studio.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.