Thank you for the detailed explanation to all of my questions! I understand the retain statement much better now. And that I need to use PUT for DATA SET vars and %PUT for macro vars.
I am still a bit confused about the CALL SYMPUTX. Let me use the same code with AVG changed to MACRO_COUNT to use as a macro variable for the DATA SET var COUNT:
%let job=Analyst;
data work.staff;
keep employeeID jobtitle salary;
set certadv.staff;
where jobtitle contains "&job";
total+salary;
count+1; put "count is " count;
call symputx('macro_count',put(count, 8.));
%put &=macro_count;
run;
I add a PUT for count and a %PUT for macr_count.
The PUT did print 1,2,3,4,5,6,7 as expected since there are 7 observations that matched the WHERE condition.
However, the %PUT only printed 7 to the log, and the result is printed before the PUT results although it appeared after the PUT statement in the code.
Here's what the book has:
CALL SYMPUTX('macro-variable', DATA-step-variable);
This form of the CALL SYMPUTX routine creates a macro variable named macro-variable and assigns to it the current value of DATA-step-variable.
If it is assigning the current value, then why didn't the %PUT print 1,2,3,4,5,6,7? So, the logic is confusing me here. Maybe I missed something and need to read this chapter again.
... View more