<?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 statement in SAS Studio</title>
    <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708811#M9622</link>
    <description>&lt;P&gt;I do not challenge it will work. But I need to figure out what is wrong with my code.&lt;/P&gt;</description>
    <pubDate>Wed, 30 Dec 2020 22:17:07 GMT</pubDate>
    <dc:creator>anming</dc:creator>
    <dc:date>2020-12-30T22:17:07Z</dc:date>
    <item>
      <title>put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708801#M9617</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data perm_student;&lt;BR /&gt;input name$ age 2.;&lt;BR /&gt;cards; &lt;BR /&gt;afred 14&lt;BR /&gt;alice 13&lt;BR /&gt;barbara 13&lt;BR /&gt;carol 14&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data student;&lt;BR /&gt;set perm_student;&lt;BR /&gt;put name $15. @5 age 2.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;it looks that 'put' does not work. The student dataset is only a simple copy of perm_student. could you help what is wrong?&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Dec 2020 21:20:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708801#M9617</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-12-30T21:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708802#M9618</link>
      <description>&lt;P&gt;I can assure you that the PUT statement works fine. It has for decades.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 21:29:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708802#M9618</guid>
      <dc:creator>WarrenKuhfeld</dc:creator>
      <dc:date>2020-12-30T21:29:43Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708807#M9619</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356091"&gt;@anming&lt;/a&gt;&amp;nbsp; I really like that&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16777"&gt;@WarrenKuhfeld&lt;/a&gt;&amp;nbsp; states "decades".&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; I am sure PUT is older than us.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anyways, here&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put name $15. @5 age 2.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You are stating write the values of name starting at column 1(&lt;EM&gt;coz this default&lt;/EM&gt;) upto 15 bytes of character specified by the width of the format i.e. 15. Then at column 5, you are explicitly telling SAS to start writing the values of age. This means you are &lt;STRONG&gt;overwriting&lt;/STRONG&gt; any value of name that is over 4 characters of length, starting with value of age in the buffer aka area of memory where SAS writes.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Correct your put statement with by removing&amp;nbsp;@5 or by writing at a much greater position of the buffer, something like&amp;nbsp;@16 that doesn't overwrite the name values.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;put name $15. age 2.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;In the above , SAS pads the chars with blanks upto 15 column positions in the buffer. I hope this helps?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 21:44:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708807#M9619</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-12-30T21:44:06Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708808#M9620</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356091"&gt;@anming&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data perm_student;&lt;BR /&gt;input name$ age 2.;&lt;BR /&gt;cards; &lt;BR /&gt;afred 14&lt;BR /&gt;alice 13&lt;BR /&gt;barbara 13&lt;BR /&gt;carol 14&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data student;&lt;BR /&gt;set perm_student;&lt;BR /&gt;put name $15. @5 age 2.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;it looks that 'put' does not work. The student dataset is only a simple copy of perm_student. could you help what is wrong?&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did you look in your &lt;STRONG&gt;log&lt;/STRONG&gt; for the results? If you do not specify another destination then PUT writes to the LOG.&lt;/P&gt;
&lt;P&gt;If you expect to see the text in the results window add a File Print; statement to tell SAS to direct the output to the default output destination. If you expect the results in a different file then you need a FILE statement with the file information such as path and name.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If that doesn't help, tell us exactly &lt;STRONG&gt;why&lt;/STRONG&gt; you think the Put statement did not work.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 21:41:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708808#M9620</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-30T21:41:35Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708810#M9621</link>
      <description>&lt;P&gt;indeed the overwriting will display that 'put' works. currently, it does not overwrite the name.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I also try to input ina formatted column input.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data perm_student;&lt;BR /&gt;input @1 name $7. &lt;BR /&gt;@9 age 2. ;&lt;BR /&gt;cards; &lt;BR /&gt;afred   14&lt;BR /&gt;alice   13&lt;BR /&gt;barbara 13&lt;BR /&gt;carol   14&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 22:15:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708810#M9621</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-12-30T22:15:43Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708811#M9622</link>
      <description>&lt;P&gt;I do not challenge it will work. But I need to figure out what is wrong with my code.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 22:17:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708811#M9622</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-12-30T22:17:07Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708813#M9623</link>
      <description>&lt;P&gt;there is nothing strange in the log file.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="sasSource"&gt;1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;72&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;73 data student;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;74 set perm_student;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;75 put name $15. @5 age 2.;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;76 run;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;afre14&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;alic13&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;barb13a&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;caro14&lt;/DIV&gt;
&lt;DIV id="sasLogNote1_1609366660344" class="sasNote"&gt;NOTE: There were 4 observations read from the data set WORK.PERM_STUDENT.&lt;/DIV&gt;
&lt;DIV id="sasLogNote2_1609366660344" class="sasNote"&gt;NOTE: The data set WORK.STUDENT has 4 observations and 2 variables.&lt;/DIV&gt;
&lt;DIV id="sasLogNote3_1609366660344" class="sasNote"&gt;NOTE: DATA statement used (Total process time):&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;real time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;cpu time 0.00 seconds&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasNote"&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;77&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;78&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;79 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;&lt;/DIV&gt;
&lt;DIV class="sasSource"&gt;91&lt;/DIV&gt;</description>
      <pubDate>Wed, 30 Dec 2020 22:19:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708813#M9623</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-12-30T22:19:18Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708815#M9624</link>
      <description>&lt;P&gt;Did you miss this in your log? This is the output from your PUT statement:&lt;/P&gt;
&lt;PRE&gt;afre14
alic13
barb13a
caro14&lt;/PRE&gt;</description>
      <pubDate>Wed, 30 Dec 2020 22:24:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708815#M9624</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2020-12-30T22:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708818#M9625</link>
      <description>&lt;P&gt;I see. These are the output in the log, which are not written to the output dataset.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 22:34:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708818#M9625</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-12-30T22:34:20Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708823#M9626</link>
      <description>&lt;P&gt;Hi:&lt;BR /&gt;I am not sure why you are running this program. The PUT statement should be writing to the SAS Log, NOT to the SAS dataset. Did you look in the SAS Log after this program ran? The OUTPUT statement writes observations to the SAS dataset in the DATA statement. The PUT statement, without a FILE reference will write to the log in the same way as the PUTLOG statement. Consider these 2 DATA steps and 2 PROC PRINTS -- the differences should be obvious when you look at the PROC PRINTS and then look at the SAS log.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data newfile;
  set sashelp.class;
  where age gt 14;
  put @1 "** From the PUT statement: " @35 name= _n_= age=;
  putlog "*** From PUTLOG statement: " name= _n_= age=;
run;

proc print data=newfile;
title 'SAS dataset work.newfile';
run;

data newfile2;
  set sashelp.class;
  where age gt 14;
  file 'c:\temp\fromput.txt';
  put @1 "** From the PUT statement: " @35 name= _n_= age=;
  putlog "*** From PUTLOG statement: " name= _n_= age=;
run;

proc print data=newfile2;
title 'SAS dataset work.newfile';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;In order to run the second program, you'll need to change the path location in the FILE statement to a location where you have write access. But you should see a noticeable difference in the LOG output and then, if you open the .TXT file that is created in the second program you'll see the results of using the PUT statement.&lt;BR /&gt;&lt;BR /&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 22:52:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708823#M9626</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-12-30T22:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708824#M9627</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/356091"&gt;@anming&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I see. These are the output in the log, which are not written to the output dataset.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;PUT does not write to the data set. Period.&lt;/P&gt;
&lt;P&gt;Put writes to log, result window or output destination files.&lt;/P&gt;
&lt;P&gt;There are no print positions in a data set to use the column modifiers like @5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want values in the data set that is a VARIABLE.&lt;/P&gt;
&lt;P&gt;So, it may be time to describe what are attempting to do.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Dec 2020 22:52:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708824#M9627</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-12-30T22:52:05Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708825#M9628</link>
      <description>Hi, As Warren explains, the PUT statement works fine -- it was one of the first statements I had to learn because my first job using SAS required me to write TEXT files that could be imported into a different mainframe application. The job of the PUT statement, however, is NOT to write to a SAS dataset. The job of the PUT statement is to write values (text strings, variable values) to a text location such as the SAS Log, an ASCII text file or sometimes, to a command stream (such as the old days with DDE).  In the "old" days, the PUT statement wrote to the SAS log in the absence of any other instructions. With a File reference, the PUT statement can write to a "flat" file or "raw" file or ASCII text file. Later, the PUTLOG statement was designed to make it explicit where text and values were being written.&lt;BR /&gt;&lt;BR /&gt;  I suspect you did not look in the SAS Log after you ran your program. Please read the documentation for the PUT statement. Your assumptions about how you write to a SAS dataset versus how you write to a flat file versus how you write to the SAS Log need clarifying and I have posted some code that should help you understand better. However, you will need to review the SAS Log and the SAS dataset that's created and the PROC PRINT output in order to really zero in on what is happening with the PUT statement.&lt;BR /&gt;Cynthia</description>
      <pubDate>Wed, 30 Dec 2020 23:02:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708825#M9628</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-12-30T23:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708837#M9629</link>
      <description>&lt;P&gt;INPUT reads text into SAS which you then can assign to a column of a table.&lt;/P&gt;
&lt;P&gt;PUT writes text to an external file and not to a data set (a table).&lt;/P&gt;
&lt;P&gt;SET reads from a table.&lt;/P&gt;
&lt;P&gt;DATA creates a new table.&lt;/P&gt;
&lt;P&gt;If you want to create a new table using an existing table then the syntax is:&lt;/P&gt;
&lt;PRE&gt;data &amp;lt;new table&amp;gt;;
   set &amp;lt;existing table&amp;gt;;
run;&lt;/PRE&gt;
&lt;P&gt;The SAS log is your friend so don't suppress the messages (like with NOnotes). When reading from external data (here what's under your cards statement) then it's worth to use an informat which creates your variable in the length you want to (=character with a length of 15 for name). Please note: For numerical variables the informat (2. for age) instructs SAS how to read the external text. The length for the variable will become 8 which is the internal storage used for storing the number. Do not attempt to change this length for numerical variables until you understand much better how things work.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;OPTIONS NOTES SOURCE SYNTAXCHECK;
data perm_student;
  input name $15. age 2.;
  cards;
afred 14
alice 13
barbara 13
carol 14
;

proc contents data=perm_student;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Patrick_0-1609375872436.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/53133i23069691017B0748/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Patrick_0-1609375872436.png" alt="Patrick_0-1609375872436.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Now after all of the above: Can you clearly express what you have and what you want to achieve? How your desired result should look like?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2020 00:58:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708837#M9629</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-12-31T00:58:37Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708840#M9630</link>
      <description>&lt;P&gt;This is a pretty old practical question. The question is "what is written to the output raw data file?". The suggested answer is&amp;nbsp;&lt;/P&gt;
&lt;P&gt;the results 'put' statement generated in the log file. This confuses me. After checking all discussions I do not think this question is well designed. Now I have a better understanding!&lt;/P&gt;</description>
      <pubDate>Thu, 31 Dec 2020 01:18:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708840#M9630</guid>
      <dc:creator>anming</dc:creator>
      <dc:date>2020-12-31T01:18:05Z</dc:date>
    </item>
    <item>
      <title>Re: put statement</title>
      <link>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708849#M9631</link>
      <description>Hi: &lt;BR /&gt;  If this question came from one of our SAS Education classes or from the certification Prep Guide or from the practice exam that is published by SAS, then please post EXACTLY where you found this question in our material so we can review it. &lt;BR /&gt;  If this question came from one of the 3rd party sites that you referred to in a previous posting, then this is the reason we don't recommend using web sites not sponsored by SAS.&lt;BR /&gt;  Please look again at the Content Guide for the Base Programmer exam, although the PUTLOG statement and the PUT function are covered on the Base Programmer exam, I believe you will find that the simple PUT statement is NOT covered on the exam. The Content Guide makes it clear what will be covered on the exam.&lt;BR /&gt;Cynthia</description>
      <pubDate>Thu, 31 Dec 2020 03:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Studio/put-statement/m-p/708849#M9631</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2020-12-31T03:00:11Z</dc:date>
    </item>
  </channel>
</rss>

