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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.