DATA Step, Macro, Functions and more

%put vs put summary question

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 133
Accepted Solution

%put vs put summary question

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?


Accepted Solutions
Solution
‎04-10-2012 03:06 PM
Super User
Posts: 5,518

Re: %put vs put summary question

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.

View solution in original post


All Replies
Contributor
Posts: 45

Re: %put vs put summary question

%Put can be in open code and doesn't need quotes.

Super User
Posts: 5,518

Re: %put vs put summary question

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.

Frequent Contributor
Posts: 133

Re: %put vs put summary question

Posted in reply to Astounding

"

%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

Solution
‎04-10-2012 03:06 PM
Super User
Posts: 5,518

Re: %put vs put summary question

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.

Frequent Contributor
Posts: 133

Re: %put vs put summary question

Posted in reply to Astounding

Excellent point, I finally got it

🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 1287 views
  • 0 likes
  • 3 in conversation