BookmarkSubscribeRSS Feed
apple
Calcite | Level 5

What are both for? What is the difference between the 2?

Thanks

5 REPLIES 5
Tom
Super User Tom
Super User

PUT statement is for writing information to a file (or the SAS log or output destination).  It has a robust syntax that allows writing data in many ways.

PUT() function is for applying a format to a value to convert it into a character string. You can use it in expressions or an assignment statement.

RichardinOz
Quartz | Level 8

To expand a little on Tom's explanation the PUT statement is used to write data from a SAS datastep into an object that is not a SAS dataset: usually an external file, or the SAS log or output areas.  It has the ability to write text strings and formatted values of datastep variables; with the ability to tab to a position or skip to a new line or new page.

The PUT() function is used to populate a variable within a SAS dataset or view with a value derived from an existing variable or expression so it needs much less functionality.  It is always used with a format specified as the second parameter, and always results in a character value whether the existing variable is numeric or character (though SAS may have to do a type conversion behind the scenes if you specify a numeric destination).

To derive a numeric value from an existing character value you need the INPUT() function with an appropriate informat.  To derive a numeric value from a numeric value you would need to nest a PUT() function inside an INPUT() function, or find a specific numeric function for the transformation you require.

There are also the PUTC() and PUTN() functions which are strictly for character and numeric expressions respectively, which you need to use with %SYSFUNC() in a macro expression. They can also be used in datastep code in the case where the format needs to be selected dynamically (eg other logic in the datastep determines which format to apply).

Richard temporarily back in Oz

umashankersaini
Quartz | Level 8

Hi Richard,

Awesome explanation.... thanks for sharing knowledge.

Regards

Uma Shanker Saini

NaveenSrinivasan
Calcite | Level 5

hi apple,

It looks like you require some sort of documentation for comprehensive understanding pf the basic concepts. I'd suggest you to google search for the free online book called step by step base sas prpgramming learning edition that has all that you need from the very basic to complex examples. Also, there is a beautiful book by author Ron Cody- SAS function by examples. I'd highly recommend referring the book.

hth,

Naveen

umashankersaini
Quartz | Level 8

Hi,

If you are unable to get the free online book and some notes, Please feel free to write an email to me.

else TOM's explanation is very useful.

Regadrs
Uma Shanker Saini

sas-innovate-2024.png

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.

 

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
  • 4855 views
  • 3 likes
  • 5 in conversation