BookmarkSubscribeRSS Feed
Babloo
Rhodochrosite | Level 12

I have multiple datasets with different names under the the same library. All the variables in those datasets are same. Now I want to query the Minimum And maximum value of particular variable of all those datasets in a step or two.

 

Appreciate if someone of you guide me here. 

8 REPLIES 8
Reeza
Super User

Assuming the data sets are the same structure and can be stacked, you can create a view and summarize that.Or you can summarize each data set individually and extract that information from the summary data.

 

data have / view=have;
set data1-data10;
run;

proc means data=have min max;
var var1-var3;
run;

@Babloo wrote:

I have multiple datasets with different names under the the same library. All the variables in those datasets are same. Now I want to query the Minimum And maximum value of particular variable of all those datasets in a step or two.

 

Appreciate if someone of you guide me here. 


 

Babloo
Rhodochrosite | Level 12
Datasets names are like employee, salary, address etc and it is not like
data1 to data2.

I failed to mention this in my initial post.
Reeza
Super User
Please post sample data and expected output.
Reeza
Super User

@Babloo wrote:
Datasets names are like employee, salary, address etc and it is not like
data1 to data2.

I failed to mention this in my initial post.

You said:

 

>All the variables in those datasets are same

 

If that true regardless of names? If so that's fine, just list the names. If not, then you have a  much more complex problem. 

PaigeMiller
Diamond | Level 26

Datasets names are like employee, salary, address etc and it is not like data1 to data2.

 

You replace the data1-data10 in the example code with the names of your actual data sets.

--
Paige Miller
andreas_lds
Jade | Level 19

Untested code:

 

proc sql noprint;
  select MemName
    into :datasetList separated by ' '
    from sashelp.vtable 
      where LibName = 'LIBNAME_ALL_UPCASE'
  ;
quit;

data have / view=have;
  set &datasetList.;
run;

Then use proc means to calculate the statistics.

ballardw
Super User

@Babloo wrote:

I have multiple datasets with different names under the the same library. All the variables in those datasets are same. Now I want to query the Minimum And maximum value of particular variable of all those datasets in a step or two.

 

Appreciate if someone of you guide me here. 


Another point to clarify, do you want the single minimum/ maximum across all of the data sets or for each dataset with an indicator of which set each max/ min is from?

svh
Lapis Lazuli | Level 10 svh
Lapis Lazuli | Level 10

Very interesting to see different approaches. I realize mine is probably less efficient than the others. I really like to use macros with CALL EXECUTE, so my strategy was to use dictionary tables (like another user did) to obtain the list of tables that need to be summarized. With this, I created a table of data set names that could be used with a CALL EXECUTE statement.  This way, the macro with PROC MEANS can run on each data set. At the end, a DATA step concatenates all of the summary tables.

 

IMPORTANT: This code assumes that your TEST library ONLY has the tables you want to use to calculate summary statistics.

 

libname test '<PATH>';

data test.A;
  input x y;
  cards;
  1 2
  3 4
  5 6
;
run;

data test.b;
  input x y;
  cards;
  7 8
  9 10
  11 12
;
run;

proc sql;
   create table macros as
   select strip(memname) as table_name from dictionary.tables
   where libname = 'TEST';
quit;

%macro means(dsn);
proc means data=Test.&dsn;
   var x;
   output max=maximum min=minimum out=Test.Summary&DSN ;
run;
data Test.Summary&DSN;
   set Test.Summary&DSN;
   dataset = "&dsn";
%mend means;  

data _null_;
set macros;
  call execute('%means('||table_name||')');
  run;

data Test.Finished;
  set Test.Summary:;
  run;

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!

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
  • 8 replies
  • 2284 views
  • 0 likes
  • 6 in conversation