DATA Step, Macro, Functions and more

How to combined two macro and make it single macro?

Reply
N/A
Posts: 1

How to combined two macro and make it single macro?

I have two pics of macro code, which perform two different task  from given parameter. I want to combined these macro in single macro. For testing purpose,I have used class data set from sashelp library.

First one:-

which will perform EDA according to the variable entered numeric or character

%macro eda_analysis(data=,var=,var1=);

      data analysis_&data;

      set sashelp.&data;

      run;

    proc contents data=work.analysis_&data out=details_&data;

  run;

  %if

%eval(&type.*1)=1 %then %do;

/* variable exploration using proc means*/

proc means data=work.analysis_&data;

var &var;

title

'Mean analysis';

run;

/*proc univariate exploration*/

proc univariate data=work.analysis_&data;

/*it gives a detail analysis of the variable,more adjustive,lot of statistics about the dataset*/

var &var;

title

'Vivid Analysis of the data';/*it also gives you an idea of how this dataset is distibuted i.e symmetric or unsymmetric*/

run;

quit;

/*to check the normality of the dataset*/

proc univariate data=work.analysis_&data;

var &var;

histogram &var;

/* histogram is basically a one way of presenting your data in a graphical form, different value in x axis and corresponding count on y axis,distribution of data across values,default is that the normality is a basic criteria*/

run;

proc univariate data=work.analysis_&data normal plot;

/*alternative way to check normality*/

var &var;

histogram &var;

qqplot &var/normal (mu=est sigma=est color=green);

run;

ods graphics on;

proc gplot data=work.analysis_&data;

plot &var * &var1;

run;

quit;

%end

;

%else

%do;

/*variable exploration using proc freq as count on categories because categorical variable std,mean wont make sense*/

proc freq data=work.analysis_&data

/*better to have a uniform frequencies between categorical variables*/;

table &var;

title

'Frequency Analysis';

run;

/*Chisquare test of independence of attributes*/

proc freq data=work.analysis_&data;

tables &var * &var1/chisq;

run;

proc freq data=work.analysis_&data;

table &var * &var1;

run;

%end

;

%mend eda_analysis;


%eda_analysis(data=class,var=height);



Second macro :-..............


data

lal;

set

  1. sashelp.class;

run

;

%macro

lst(datasetname);

%local datasetid count rc;

%global x;

%let x=;

/* Open the data set */

%let datasetid=%sysfunc(open(&datasetname));

/* The variable count will contain the number of variables that are in the */

/* data set that is passed in. */

%let count=%sysfunc(attrn(&datasetid,nvars));

/* Create a macro variable that contains all dataset variables */

%do i = 1 %to &count;

%let x=&x %sysfunc(varname(&datasetid,&i));

%end;

/* Close the data set */

/* %let rc=%sysfunc(close(&datasetid)); */

%mend

lst;

/* Pass in the name of the data set */

%lst(lal)

%put

macro variable x cotains the list= &x;




Now I want implemented this macro inside a single macro so that whenever a user gives a dataset name and the variable to be analyzed it will perform according to it.


Thanks



Super User
Super User
Posts: 7,074

Re: How to combined two macro and make it single macro?

Posted in reply to lal06mohan

You need a much clearer design than that.

Why not just generate a new macro that calls the old ones?

Super User
Super User
Posts: 7,977

Re: How to combined two macro and make it single macro?

I agree with the clearer design, TBH in the original code there I don't even see the need for macro code.

Personally I can't agree with the second point though about creating a wrapper around two macros, I have seen this about where macros call macros which call other ones and the wrapping goes on and on until your having to copy 30mb of macro code across just because you don't know which ones are needed.

Am sure all that would defined in the Functional Design Specification and Testing documentation which you create before writing general macros of course Smiley Surprised)

Ask a Question
Discussion stats
  • 2 replies
  • 232 views
  • 0 likes
  • 3 in conversation