For SAS programmers, the PUT statement in the DATA step and the %PUT macro statement are useful statements that enable you to display the values of variables and macro variables, respectively. By default, the output appears in the SAS log. This article shares a few tips that help you to use these statements more effectively.

### Tip 1: Display the name and value of a variable

The PUT statement supports a "named output" syntax that enables you to easily display a variable name and value. The trick is to put an equal sign immediately after the name of a variable: PUT varname=; For example, the following statement displays the text "z=" followed by the value of z:

```data _null_; x = 9.1; y = 6; z = sqrt(x**2 + y**2); put z=; /* display variable and value */ run;```
`z=10.9`

### Tip 2: Display values of arrays

You can extend the previous tip to arrays and to sets of variables. The PUT statement enables you to display elements of an array (or multiple variables) by specifying the array name in parentheses, followed by an equal sign in parentheses, as follows:

```data _null_; array x; do k = 1 to dim(x); x[k] = k**2; end; put (x[*]) (=); /* put each element of array on separate lines */ put (x1 x3 x5) (=); /* put each variable/value on separate lines */ run;```
```x1=1 x2=4 x3=9 x4=16 x5=25 x1=1 x3=9 x5=25```

This syntax is not supported for _TEMPORARY_ arrays. However, as a workaraoun, you can use the CATQ function to concatenate array values into a character variable, as follows:

```temp = catq('d', ',', of x[*]); /* x can be _TEMPORARY_ array */ put temp=;```

Incidentally, if you ever want to apply a format to the values, the format name goes inside the second set of parentheses, after the equal sign: put (x1 x3 x5) (=6.2);

### Tip 3: Display values on separate lines

The previous tip displayed all values on a single line. Sometimes it is useful to display each value on its own line. To do that, put a slash after the equal sign, as follows:

```... put (x[*]) (=/); /* put each element on separate lines */ ...```
```x1=1 x2=4 x3=9 x4=16 x5=25```

### Tip 4: Display all name-value pairs

You can display all values of all variables by using the _ALL_ keyword, as follows:

```data _null_; x = 9.1; y = 6; z = sqrt(x**2 + y**2); A = "SAS"; B = "Statistics"; put _ALL_; /* display all variables and values */ run;```
`x=9.1 y=6 z=10.9 A=SAS B=Statistics _ERROR_=0 _N_=1`

Notice that in addition to the user-defined variables, the _ALL_ keyword also prints the values of two automatic variables named _ERROR_ and _N_.

### Tip 5: Display the name and value of a macro variable

Just as the PUT statement displays the value of an ordinary variable, you can use the %PUT statement to display the value of a macro variable. If you use the special "&=" syntax, SAS will display the name and value of a macro variable. For example, to display your SAS version, you can display the value of the SYSVLONG automatic system macro variable, as follows:

`%put &=SYSVLONG;`
```SYSVLONG=9.04.01M4P110916
```

The results above are for my system, which is running SAS 9.4M4. Your SAS version might be different.

### Tip 6: Display all name-value pairs for macros

You can display the name and value of all user-defined macros by using the _USER_ keyword. You can display the values of all SAS automatic system macros by using the _AUTOMATIC_ keyword.

```%let N = 50; %let NumSamples = 1e4; %put _USER_;```
```GLOBAL N 50
GLOBAL NUMSAMPLES 1e4
```

### Conclusion and References

There you have it: six tips to make it easier to display the value of SAS variables and macro variables. Thanks to Jiangtang Hu who pointed out the %PUT &=var syntax in his blog in 2012. For additional features of the PUT and %PUT statements, see:

The post PUT it there! Six tips for using PUT and %PUT statements in SAS appeared first on The DO Loop.
{"ft_lang_label":"__label__en","ft_lang_prob":0.723838,"math_prob":0.9745827,"size":3806,"snap":"2021-31-2021-39","text_gpt3_token_len":1008,"char_repetition_ratio":0.16570227,"word_repetition_ratio":0.08064516,"special_character_ratio":0.28192326,"punctuation_ratio":0.13349815,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99031746,"pos_list":[0,1,2],"im_url_duplicate_count":[null,2,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-08-01T23:01:02Z\",\"WARC-Record-ID\":\"<urn:uuid:5cecfb9c-b13a-43ea-9729-dfc8cccb99c8>\",\"Content-Length\":\"40120\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:46490c4c-65b2-4b56-a88a-df703f5bcf42>\",\"WARC-Concurrent-To\":\"<urn:uuid:71614237-6904-485d-9ded-170c3d47e1c5>\",\"WARC-IP-Address\":\"23.229.128.39\",\"WARC-Target-URI\":\"http://saslist.com/blog/2017/01/16/put-it-there-six-tips-for-using-put-and-put-statements-in-sas/\",\"WARC-Payload-Digest\":\"sha1:JIFQDTLQ6XDK5AQY6DNSN2FSGL52F5LN\",\"WARC-Block-Digest\":\"sha1:75OD5ZJJOEUGYTBRQ5BEMF6VD4K4XGL4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-31/CC-MAIN-2021-31_segments_1627046154277.15_warc_CC-MAIN-20210801221329-20210802011329-00649.warc.gz\"}"}