<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Put Function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259083#M50055</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Further down in the function explanation you can find:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellpadding="0" cellspacing="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Details&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the PUT function returns a value to a variable that has not yet been assigned a length, by default the variable length is determined by the width of the format.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Use PUT to convert a numeric value to a character valu&lt;/STRONG&gt;e. The PUT function has no effect on which formats are used in PUT statements or which formats are assigned to variables in data sets. You cannot use the PUT function to change the type of a variable in a data set from numeric to character.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Mar 2016 15:23:06 GMT</pubDate>
    <dc:creator>Loko</dc:creator>
    <dc:date>2016-03-25T15:23:06Z</dc:date>
    <item>
      <title>Put Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259081#M50053</link>
      <description>&lt;P&gt;Can someone explain what the use of the Put function? I thought it converts &lt;STRONG&gt;&lt;U&gt;numeric data values to character data values&lt;/U&gt;&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I read&amp;nbsp;in the below link&amp;nbsp;that it only re-formats. Since the format&amp;nbsp;must be of the same type as the source, either character or numeric. How does it convert a numeric to a character?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000199354.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000199354.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE width="100%" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR valign="top"&gt;
&lt;TD&gt;
&lt;H2&gt;&lt;A name="a002505289" target="_blank"&gt;&lt;/A&gt;Syntax&lt;/H2&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;TABLE cellspacing="2" cellpadding="4"&gt;
&lt;TBODY&gt;
&lt;TR valign="top"&gt;
&lt;TD&gt;
&lt;TABLE cellspacing="2" cellpadding="2"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="24"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&lt;SPAN class="strong"&gt;PUT&lt;/SPAN&gt;(&lt;SPAN class="emph"&gt;source&lt;/SPAN&gt;, &lt;SPAN class="emph"&gt;format&lt;/SPAN&gt;.)&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&lt;A name="a002895412" target="_blank"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;A name="a002505290" target="_blank"&gt;&lt;/A&gt;Arguments&lt;/H3&gt;
&lt;P&gt;&lt;A name="a000845528" target="_blank"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;DL&gt;
&lt;DT&gt;&lt;SPAN class="strong"&gt;&lt;A name="a000845529" target="_blank"&gt;&lt;/A&gt;&lt;SPAN class="strongEmph"&gt;source&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/DT&gt;
&lt;DD&gt;
&lt;P&gt;&lt;A name="a000845530" target="_blank"&gt;&lt;/A&gt;identifies the constant, variable, or expression whose value you want to reformat. The &lt;SPAN class="strongEmph"&gt;source&lt;/SPAN&gt; argument can be character or numeric.&lt;/P&gt;
&lt;/DD&gt;
&lt;DT&gt;&lt;SPAN class="strong"&gt;&lt;A name="a000845531" target="_blank"&gt;&lt;/A&gt;&lt;SPAN class="strongEmph"&gt;format&lt;/SPAN&gt;.&lt;/SPAN&gt;&lt;/DT&gt;
&lt;DD&gt;
&lt;P&gt;&lt;A name="a000845532" target="_blank"&gt;&lt;/A&gt;contains the SAS format that you want applied to the value that is specified in the source. This argument must be the name of a format with a period and optional width and decimal specifications, not a character constant, variable, or expression. By default, if the source is numeric, the resulting string is right aligned, and if the source is character, the result is left aligned. To override the default alignment, you can add an alignment specification to a format:&lt;/P&gt;
&lt;TABLE class="largeSpace" cellspacing="0" cellpadding="5"&gt;
&lt;TBODY&gt;
&lt;TR align="left" valign="top"&gt;
&lt;TD&gt;&lt;A name="a000845533" target="_blank"&gt;&lt;/A&gt;-L&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;&lt;A name="a000845534" target="_blank"&gt;&lt;/A&gt;left aligns the value.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR align="left" valign="top"&gt;
&lt;TD&gt;&lt;A name="a000845535" target="_blank"&gt;&lt;/A&gt;-C&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;&lt;A name="a000845536" target="_blank"&gt;&lt;/A&gt;centers the value.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR align="left" valign="top"&gt;
&lt;TD&gt;&lt;A name="a000845537" target="_blank"&gt;&lt;/A&gt;-R&lt;/TD&gt;
&lt;TD align="left"&gt;
&lt;P&gt;&lt;A name="a000845538" target="_blank"&gt;&lt;/A&gt;right aligns the value.&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;TABLE cellspacing="2" cellpadding="4"&gt;
&lt;TBODY&gt;
&lt;TR valign="top"&gt;
&lt;TD width="95" align="left" class="label"&gt;Restriction:&lt;/TD&gt;
&lt;TD align="left" class="bgBlockLight"&gt;&lt;A name="a000845539" target="_blank"&gt;&lt;/A&gt; The &lt;SPAN class="strongEmph"&gt;format&lt;/SPAN&gt;. must be of the same type as the source, either character or numeric. That is, if the source is character, the format name must begin with a dollar sign, but if the source is numeric, the format name must not begin with a dollar sign.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DD&gt;
&lt;/DL&gt;</description>
      <pubDate>Fri, 25 Mar 2016 15:17:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259081#M50053</guid>
      <dc:creator>apple</dc:creator>
      <dc:date>2016-03-25T15:17:46Z</dc:date>
    </item>
    <item>
      <title>Re: Put Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259083#M50055</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Further down in the function explanation you can find:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE cellpadding="0" cellspacing="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Details&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the PUT function returns a value to a variable that has not yet been assigned a length, by default the variable length is determined by the width of the format.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Use PUT to convert a numeric value to a character valu&lt;/STRONG&gt;e. The PUT function has no effect on which formats are used in PUT statements or which formats are assigned to variables in data sets. You cannot use the PUT function to change the type of a variable in a data set from numeric to character.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 15:23:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259083#M50055</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-03-25T15:23:06Z</dc:date>
    </item>
    <item>
      <title>Re: Put Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259084#M50056</link>
      <description>&lt;P&gt;The Put function has two different behaviors depending on use.&lt;/P&gt;
&lt;P&gt;A simple Put statement writes data to the default output destination (log or destination specified in a File statement).&lt;/P&gt;
&lt;P&gt;The other is to create a character value, there will usually be an = involved here.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Newvar = put(somevariablename, UsingThisFormat.);&lt;/P&gt;
&lt;P&gt;For a fun example try this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data junk;
   x = 25;
   newx = put(x,date9.);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you run Proc Contents or use the SAS Explorer to examine the Junk data set you will see that NewX is a charater variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if a format isn't specified SAS will make a guess. The result is character.&lt;/P&gt;
&lt;P&gt;You can use put in comparison:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If ( put(somevariablename, UsingThisFormat.) ='Some formatted value' ) then do; &amp;lt;some code&amp;gt;; end;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It can create a different character value from a character depending on the nature of the specific format used.&lt;/P&gt;
&lt;P&gt;If you want t&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 15:26:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259084#M50056</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-03-25T15:26:33Z</dc:date>
    </item>
    <item>
      <title>Re: Put Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259087#M50057</link>
      <description>&lt;P&gt;The PUT() function applies a format to a value. &amp;nbsp;Since formats are used for displaying values in output they always return character strings. &amp;nbsp;This is similar to using the PUT statement to write out data. You can apply a numeric format to a numeric value or apply a character format to a character value, but either way the result is a character string. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The INPUT() function can by used to convert a character string to either a numeric or character value based on the informat that is used. &amp;nbsp;This is similar to reading data using the INPUT statement.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 15:50:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259087#M50057</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-03-25T15:50:31Z</dc:date>
    </item>
    <item>
      <title>Re: Put Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259100#M50062</link>
      <description>&lt;P&gt;Here's an example of the PUT function to perform these conversions:&lt;/P&gt;
&lt;P&gt;1) numeric variable to character variable&lt;/P&gt;
&lt;P&gt;2) character variable to character variable&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Of course the most frequent use of the PUT function is to convert a numeric value to a character string to create a new character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; Here's the code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data showstart;
x=1;
y = today();
z = 'KTF';
output;
x=2;
y=today() - 1;
z='E';
output;
x=3;
y=today() -30;
z='MP';
output;
run;
       
proc print data=showstart;
  title '1) Beginning data, no formats, before using PUT function';
run;
     
proc format;
  value xfmt 1='1. First, on' 
             2='2. Yesterday, on' 
			 3='3. Before that, on';
 
  value $zfmt 'KTF' = 'Kermit the Frog'
             'E' = 'Elmo'
			 'MP' = 'Miss Piggy';
run;
  
   
data newput;
  length newx $50 newy $50 newz $50 sentence $90;
  set showstart;
  ** numeric to character;
  newx = put(x,xfmt.);

  ** numeric to character using SAS date format;
  newy = put(y, worddate.);
   
  ** character to character;
  newz = put(z, $zfmt.);
  sentence = catx(' ',newx, newy, "Jane's favorite stuffed animal was", newz);
run;
  
proc print data=newput;
  title '2) After making new variables with PUT and using the new variables to make another variable';
  var x y z newx newy newz sentence;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's the output:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/2480i0C5095B2FB15E394/image-size/original?v=mpbl-1&amp;amp;px=-1" alt="PUT_function.png" title="PUT_function.png" border="0" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 17:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259100#M50062</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2016-03-25T17:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Put Function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259190#M50096</link>
      <description>&lt;P&gt;You may find this SAS Sample note helpful too...&amp;nbsp;&lt;A href="http://support.sas.com/kb/24/590.html" target="_blank"&gt;http://support.sas.com/kb/24/590.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind Regards,&lt;/P&gt;
&lt;P&gt;Michelle&lt;/P&gt;</description>
      <pubDate>Fri, 25 Mar 2016 22:52:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Put-Function/m-p/259190#M50096</guid>
      <dc:creator>MichelleHomes</dc:creator>
      <dc:date>2016-03-25T22:52:03Z</dc:date>
    </item>
  </channel>
</rss>

