BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
alepage
Barite | Level 11

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?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

4 REPLIES 4
PaigeMiller
Diamond | Level 26

Can we see the entire code?

 

How could this work anyway? There is no variable named transaction_dt in data set &nsource.

--
Paige Miller
Reeza
Super User
PROC MEANS/SUMMARY are the most efficent.
ballardw
Super User

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.

alepage
Barite | Level 11

It's awesome. Also, as I am not familiar with the set & memlist option. indsname = dsn; I will add a reference: https://blogs.sas.com/content/iml/2015/08/03/indsname-option.html

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1216 views
  • 3 likes
  • 4 in conversation