<<< Click here to go back
2. Data Step - Call Symput Method :
Understand by example and utility :
Suppose we have a data :
Data marks_data;
input name $ marks;
datalines;
Ramesh 75
Suresh 78
Seeta 81
Geeta 84
;
run;
Proc print ;
Run;
Scenario 1 : We need to assign a Macro Variable third name of data as value. Let's use data step method for the same :
Data _null_;
set marks_data;
if _n_ = 3 then
call symput('thirdname',name);
run;
%Put Name of first student in the list is &thirdname. ;
Let's understand it with one more usage ...
Scenario 2 : Assign the students names into 4 macro variables , First one into Student_1, second into Student_2 and so on.
Data _null_;
set marks_data ;
call symput('Student_'!!put(_n_,10. -L), name);
Run;
%Put &student_1.;
%Put &student_2.;
%Put &student_3.;
%Put &student_4.;
Scenario 3 : Assign the name of the student, who has secured highest marks, to a Macro Variable.
Proc sort data=marks_data ;
by descending marks ;
run;
data _null_;
set marks_data;
if _n_ = 1 then
call symput('topper',name);
run;
%put Name of first student in the list &topper.;
It is very easy, right, you just need to use tricks and common sense.
Suppose we have a data :
Data marks_data;
input name $ marks;
datalines;
Ramesh 75
Suresh 78
Seeta 81
Geeta 84
;
run;
Proc print ;
Run;
Scenario 1 : We need to assign a Macro Variable third name of data as value. Let's use data step method for the same :
Data _null_;
set marks_data;
if _n_ = 3 then
call symput('thirdname',name);
run;
%Put Name of first student in the list is &thirdname. ;
Let's understand it with one more usage ...
Scenario 2 : Assign the students names into 4 macro variables , First one into Student_1, second into Student_2 and so on.
Data _null_;
set marks_data ;
call symput('Student_'!!put(_n_,10. -L), name);
Run;
%Put &student_1.;
%Put &student_2.;
%Put &student_3.;
%Put &student_4.;
Scenario 3 : Assign the name of the student, who has secured highest marks, to a Macro Variable.
Proc sort data=marks_data ;
by descending marks ;
run;
data _null_;
set marks_data;
if _n_ = 1 then
call symput('topper',name);
run;
%put Name of first student in the list &topper.;
It is very easy, right, you just need to use tricks and common sense.
No comments:
Post a Comment
Do provide us your feedback, it would help us serve your better.