SAS Macro 7

<<< Click here to go back


All right, We have learnt various ways of creating macro variable, also we have learnt how to resolve these variable and print their values in Log (using %put option). Let us now understand how to use these in useful SAS programs.

Suppose we have a data set :

Data Class;
infile datalines ;
Input Name $ Subject $ full_marks Marks_secured;
cards;
Rajat Maths 100 52
Vinod Maths 100 64
Rakesh Maths 100 57
Geeta Maths 100 58
Bharat Maths 100 86
Rajesh Maths 100 81
Monal Maths 100 67
Aarya Maths 100 88
Ritesh Maths 100 68
Neha Maths 100 88
Rajat English 150 53
Vinod English 150 69
Rakesh English 150 52
Geeta English 150 59
Bharat English 150 88
Rajesh English 150 59
Monal English 150 71
Aarya English 150 66
Ritesh English 150 68
Neha English 150 77
;
Run;

Usage Example 1


We need to create data of an individual student on request.

Suppose First request comes for data of Aarya, you would write the code as :

Data Aarya_data;
set  Class;
where name = "Aarya";
Run;


Second request comes for Neha, you would not write the code :

Data Neha_data;
set  Class;
where name = "Neha";
Run;

Since, it is a repetitive task, we should think of making a macro of it  right ? This a very small data and small code, however in real industry problem, both data and code would be large. In that case, changing some parameter's ("name" here) in code would be difficult.

So let's use Global Macro functionality here :



Now you just need to change the assignment of value in %let statement and you would be done.


We would understand more usage of Local Macro variables further once we complete the Macro and Local Macro Variable part.


Enjoy reading our other articles and stay tuned with ...

Kindly do provide your feedback in the 'Comments' Section and share as much as possible.



Family of Macro related articles :





4.  Conditional execution in Macro

5.  Much more

No comments:

Post a Comment

Do provide us your feedback, it would help us serve your better.