BookmarkSubscribeRSS Feed
lal06mohan
Calcite | Level 5

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



2 REPLIES 2
Tom
Super User Tom
Super User

You need a much clearer design than that.

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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 :O)

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
  • 2 replies
  • 723 views
  • 0 likes
  • 3 in conversation