BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
ZRick
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

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

5 REPLIES 5
Jay_TxOAG
Quartz | Level 8

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

Astounding
PROC Star

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.

ZRick
Obsidian | Level 7

"

%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

Astounding
PROC Star

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.

ZRick
Obsidian | Level 7

Excellent point, I finally got it

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 3983 views
  • 2 likes
  • 3 in conversation