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

Hi SAS friends,

     I have multiple datasets that i would like to send to proc summary. I can get the dataset names into a macro variable but can't quite figure out how to send it to proc summary. below is pseudo code, thank you.

data class1 class2;

  set sashelp.class;

run;

proc sql noprint;

  select memname into: list separated by ' '

  from dictionary.tables

  where libname = 'WORK' and memname contains 'CLASS';

quit;

proc summary data = &list.;

  var _numeric_;

  output out = &list._sum sum=;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

Call execute is an easy way to do what you want.  e.g.:

data class1 class2;

  set sashelp.class;

run;

proc sql noprint;

  create table flist as

    select memname

       from dictionary.tables

        where libname = 'WORK' and

              memname contains 'CLASS';

quit;

data _null_;

  set flist;

    call execute("proc summary data ="||

      trim(memname)||"; var _numeric_;output out="||

      trim(memname)||"_sum sum=;run;");

run;

View solution in original post

5 REPLIES 5
art297
Opal | Level 21

Call execute is an easy way to do what you want.  e.g.:

data class1 class2;

  set sashelp.class;

run;

proc sql noprint;

  create table flist as

    select memname

       from dictionary.tables

        where libname = 'WORK' and

              memname contains 'CLASS';

quit;

data _null_;

  set flist;

    call execute("proc summary data ="||

      trim(memname)||"; var _numeric_;output out="||

      trim(memname)||"_sum sum=;run;");

run;

TomKari
Onyx | Level 15

Interesting!

Are there any limits to how many steps you can "push" into the SAS queue with CALL EXECUTE?

Tom

Tom
Super User Tom
Super User

There might be, but I would suspect it is quite large.  If you are generating macro calls then use %NRSTR() so that only the call is pushed onto the stack and not all of the code that it generates. Note that this trick also solves some timing issues that can occur when macros are executed by SAS as they are pushed onto the stack by CALL EXECUTE, but the actual generated code is not called until after the current datastep tops.

You can avoid this by just writing the code to temporary file and including it instead of using CALL EXECUTE.  This has two other advantages.

1) PUT statement syntax is much more flexible for generating the code.

2) You can generate the file and view its contents to verify that you are generating the code properly.

filename code temp;

data _null_;

  set list;

  put ..... ;

run;

%inc code /source2 ;

data_null__
Jade | Level 19

I wonder if there is any advantage to just using SASHELP.VTABLE in the data step with CALL EXECUTE. 

art297
Opal | Level 21

DN: Obviously!  I didn't think about it as I was just following the OP's originally proposed steps but, like you ask, that proc sql run isn't necessary.

: If there are any such limits, I'm not aware of them.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 2275 views
  • 1 like
  • 5 in conversation