difference between these two programs? why does mfirst value changes?

Reply
Occasional Contributor
Posts: 17

difference between these two programs? why does mfirst value changes?

Given the SAS data set ONE:
ONE
DIVISION  SALES
A                1234
A                3654
B                5678

 

Program 1:


Data_null_;
Set one;
By division;
If first.division then
Do;
%let mfirst=sales;
end;
run;

 

Program 2

 

data _null_;
set one;
by division;
if first.division then
call symput('mfirst',sales);
run;

 

Why does the value of mirst changes in the two programs?? what is the signicant difference for the change in value?

 

Respected Advisor
Posts: 4,998

Re: difference between these two programs? why does mfirst value changes?

A %LET statement is never part of a DATA step.  You might as well have coded your first program as:

 

%let mfirst=sales;

Data_null_;
Set one;
By division;
If first.division then
Do;
end;
run;

 

The value assigned to MFIRST will be the five characters:  sales

 

The second program takes the value of the DATA step variable SALES and uses it to replace MFIRST.  It may do this repeatedly, so the final value assigned to MFIRST will be the only value available when the DATA step completes.

Grand Advisor
Posts: 10,239

Re: difference between these two programs? why does mfirst value changes?

Expanding slightly on @Astounding's response: Mfirst will have the value associated with the value of the Sales variable for the first record of the LAST Division encountered in the data.

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