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

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

SAS Enterprise Guide vs. SAS Studio

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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