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

Hi,

 

I wanted to run data audit( descriptive checks using either proc means/summary), where i want to automate the process.

I had a data set, executed Proc Contents and segregated data for numeric and character variables. I am stuck on how to pass the variable name to Proc means. Please help

1 ACCEPTED SOLUTION

Accepted Solutions
error_prone
Barite | Level 11

You can extract the variable names form sashelp.vcolum and save them in a macro variable and use that variable in proc means:

 

proc sql noprint;
   select Name
      into :num_vars separated by " "
      from sashelp.vcolumn
         where LIBNAME = "SASHELP" and MemName = "CLASS" and lowcase(Type) = "num"
   ;
   select Name
      into :char_vars separated by " "
      from sashelp.vcolumn
         where LIBNAME = "SASHELP" and MemName = "CLASS" and lowcase(Type) = "char" and lowcase(Name) ^= "name"
   ;
quit;

%put &num_vars;
%put &char_vars;

proc means data=sashelp.class mean;
   class &char_vars;
   var &num_vars;
run;

View solution in original post

3 REPLIES 3
RW9
Diamond | Level 26 RW9
Diamond | Level 26

You may want to provide specific examplpes - code/test data (form of a datastep).  There are of course many ways to address a problem, but probably the simplest in this case is to forget getting lists of variables and do:

proc means...;  
  var _numeric_;
...
run;

There is also a _character_ version.  Basically that means a list of all numeric or character variables.

 

If its more complicated then maybe call execute:

data _null_;
  set sashelp.vcolumn (where=(libname="WORK" and memname="ABC"));
  if type="char" then call execute('proc freq...;');
  else call execute('proc means...;');
run;
error_prone
Barite | Level 11

You can extract the variable names form sashelp.vcolum and save them in a macro variable and use that variable in proc means:

 

proc sql noprint;
   select Name
      into :num_vars separated by " "
      from sashelp.vcolumn
         where LIBNAME = "SASHELP" and MemName = "CLASS" and lowcase(Type) = "num"
   ;
   select Name
      into :char_vars separated by " "
      from sashelp.vcolumn
         where LIBNAME = "SASHELP" and MemName = "CLASS" and lowcase(Type) = "char" and lowcase(Name) ^= "name"
   ;
quit;

%put &num_vars;
%put &char_vars;

proc means data=sashelp.class mean;
   class &char_vars;
   var &num_vars;
run;
Astounding
PROC Star

The simplest possibility of all:  remove the VAR statement from PROC MEANS.  The default action is to process all numeric variables.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 1034 views
  • 1 like
  • 4 in conversation