just want to summarize put vs %put,
This code I thought can summarize where to use %put or put and what it means to data step variable, macro variable, char string
%let x=toyota;
%macro m;
%put &x;
put &x;
data _null_;
put 'x';
put x;
%put "&x";
run;
%mend;
%m
put has to be inside the the data step,
%put can be anywhere inside data step or macro
am I understanding that correctly?
Not really. It doesn't cause an error, but %PUT is not part of the DATA step. You can see that by looking at the order of the messages in the log. Even though the %PUT statement appears just before the RUN statement, the message from %PUT prints first, before the DATA step begins to execute. The %PUT statement could have appeared before the DATA step, after the DATA step, or in the middle of the DATA step, and it would have written the same message. The only connection between the DATA step and %PUT would be if the DATA step uses CALL SYMPUT to change the value of &X.
%Put can be in open code and doesn't need quotes.
ZRick,
PUT can write text strings, as well as values found in the DATA step variables.
%PUT can write text strings only (including the values of macro variables), NEVER the contents of a DATA step. You might utilize other tools such as CALL SYMPUT to transfer information from a DATA step to a macro variable. After that, %PUT can write the macro variable's value.
Good luck.
"
%PUT can write text strings only (including the values of macro variables), NEVER the contents of a DATA step.
"
But it is still useable by putting %put inside the data step right? I mean, at least sas didn't report error
Not really. It doesn't cause an error, but %PUT is not part of the DATA step. You can see that by looking at the order of the messages in the log. Even though the %PUT statement appears just before the RUN statement, the message from %PUT prints first, before the DATA step begins to execute. The %PUT statement could have appeared before the DATA step, after the DATA step, or in the middle of the DATA step, and it would have written the same message. The only connection between the DATA step and %PUT would be if the DATA step uses CALL SYMPUT to change the value of &X.
Excellent point, I finally got it
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.