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

%macro lib(lib=);
proc sql noprint;
select memname,nvar,nobs
into :     m1, :     v1, :     o1
from dictionary.tables
  where libname="%upcase(&lib)" and memtype='DATA';
quit;
%put _user_;
%mend lib;

%lib(lib=work)


This macro will give the no;of obs and no:of vars of the 1st dataset in a library...
But I need to write a macro which gives the no:of obs and no:of vars of all the datasets in a library...Please help

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

How to you want the information formatted?

You could put them into those same three macro variables as delimited values.

select memname

     , nvar

     , nobs

  into :m1 separated by ' '

     , :v1 separated by ' '

     , :o1 separated by ' '


Or you could generated multiple variables.


select memname

     , nvar

     , nobs

  into :m1 - :m999999

     , :v1 - :v999999

     , :o1 - : o999999

...

%let n=&sqlobs;



There is one difficulty with doing this as a macro since by default to new macro variables will be local to the macro and hence not available when the macro ends.  You could force them into the GLOBAL symbol table.  In which case it might be easier to do using CALL SYMPUTX.


data _null_;

   if eof then call symputx('n',_N_-1,'G');

   set sashelp.vtable end=eof;

   where libname = %upcase("&lib") ;

   call symputx(cats('m',_n_),memname ,'G') ;

  call symputx(cats('v',_n_),nvar ,'G') ;

  call symputx(cats('o',_n_),nobs ,'G') ;

run;

View solution in original post

1 REPLY 1
Tom
Super User Tom
Super User

How to you want the information formatted?

You could put them into those same three macro variables as delimited values.

select memname

     , nvar

     , nobs

  into :m1 separated by ' '

     , :v1 separated by ' '

     , :o1 separated by ' '


Or you could generated multiple variables.


select memname

     , nvar

     , nobs

  into :m1 - :m999999

     , :v1 - :v999999

     , :o1 - : o999999

...

%let n=&sqlobs;



There is one difficulty with doing this as a macro since by default to new macro variables will be local to the macro and hence not available when the macro ends.  You could force them into the GLOBAL symbol table.  In which case it might be easier to do using CALL SYMPUTX.


data _null_;

   if eof then call symputx('n',_N_-1,'G');

   set sashelp.vtable end=eof;

   where libname = %upcase("&lib") ;

   call symputx(cats('m',_n_),memname ,'G') ;

  call symputx(cats('v',_n_),nvar ,'G') ;

  call symputx(cats('o',_n_),nobs ,'G') ;

run;

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
  • 1 reply
  • 865 views
  • 0 likes
  • 2 in conversation