<?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: want to understand some code writing in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483655#M125449</link>
    <description>&lt;P&gt;Thanks. The answer about length changing makes sense. I did not realize it before.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although visitnum not shown in CHILDREN dataset, but 'visitnum=.' must be meaningful here, since I could see a difference with original code (also not include visitnum).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thanks for answering the question.&lt;/P&gt;</description>
    <pubDate>Fri, 03 Aug 2018 02:58:53 GMT</pubDate>
    <dc:creator>xiangpang</dc:creator>
    <dc:date>2018-08-03T02:58:53Z</dc:date>
    <item>
      <title>want to understand some code writing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483648#M125445</link>
      <description>&lt;P&gt;I saw this following code today. But I could not figure out the purpose of some code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One is&amp;nbsp;why use 'visitnum=.;' here.&amp;nbsp; There is no difference with this sample code. But with the original data, there is a difference between code with &lt;SPAN&gt;'visitnum=.;'&lt;/SPAN&gt; and code without&amp;nbsp;&lt;SPAN&gt;'visitnum=.;' Does anyone meeting this kind thing before?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another is&amp;nbsp;why use&amp;nbsp; '(rename=(city=city2))' and 'city=city2;' &amp;nbsp; I think it is not necessary.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data children;&lt;BR /&gt;input id city$ age day$ symptom @@;&lt;BR /&gt;output;&lt;BR /&gt;datalines;&lt;BR /&gt;1 steelcity 8 day0 1 &lt;BR /&gt;2 steelcity 8 day2 1 &lt;BR /&gt;3 steelcity 8 day2 1 &lt;BR /&gt;4 greenhills 8 day0 0 &lt;BR /&gt;5 steelcity 8 day0 0 &lt;BR /&gt;6 greenhills 8 . 1&amp;nbsp; &lt;BR /&gt;7 steelcity 8 . 1 &lt;BR /&gt;8 greenhills 8 day1 0 &lt;BR /&gt;9 greenhills 8 day2 1 &lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;
data try;
set children (rename=(city=city2)); 
length city$50.; 
city=city2;
visitnum=.;

if day='day0' then visitnum=0;
if day='day1' then visitnum=1;
if day='day2' then visitnum=2;

keep id city i age day symptom visitnum; 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 03 Aug 2018 02:41:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483648#M125445</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-03T02:41:21Z</dc:date>
    </item>
    <item>
      <title>Re: want to understand some code writing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483649#M125446</link>
      <description>&lt;P&gt;You're right about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;visitnum=.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It serves no purpose here.&amp;nbsp; It might serve a purpose if VISITNUM were part of the incoming CHILDREN data set.&amp;nbsp; But we can see from the program that VISITNUM gets created within TRY.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The renaming and copying of CITY is designed to give CITY a longer length.&amp;nbsp; In CHILDREN, CITY has a length of 8.&amp;nbsp; It would be simpler to forget about the renaming and copying, and just add this statement instead:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length city $ 50;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That statement could go either before the INPUT statement that creates CHILDREN, or before the SET statement that creates TRY.&amp;nbsp; Most likely, the programmer tried to include it where it now appears, after the SET statement.&amp;nbsp; That would be an illegal statement, trying to re-set the length of a character variable after the SET statement has already assigned a length.&amp;nbsp; So the combination that you see was all that the programmer could figure out as a way to change the length of CITY.&amp;nbsp; But a properly placed LENGTH statement could have done the trick.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 02:46:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483649#M125446</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-03T02:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: want to understand some code writing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483655#M125449</link>
      <description>&lt;P&gt;Thanks. The answer about length changing makes sense. I did not realize it before.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Although visitnum not shown in CHILDREN dataset, but 'visitnum=.' must be meaningful here, since I could see a difference with original code (also not include visitnum).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Again, thanks for answering the question.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 02:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483655#M125449</guid>
      <dc:creator>xiangpang</dc:creator>
      <dc:date>2018-08-03T02:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: want to understand some code writing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483669#M125457</link>
      <description>&lt;P&gt;The reason for using rename and length to change the length of "city" is maintaining the order of variables. Order matters if, e.g., later in the program proc export is used and the order of variables in the exported file must not change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The variable "i" should be removed from the keep statement, because it is not used in the datastep at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"visitnum=.;" would server a purpose if the author tried to extract the number from day, but wanted visitnum as numeric without using the proper converting function. Just guessing &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If there are more than three values possible for visitnum, replacing the if-then-logic with a single assignment will help keeping the code short:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;visitnum = input(substr(day, 4), best.);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Assuming that the word "day" is always in the variable "day".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 05:12:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483669#M125457</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-08-03T05:12:40Z</dc:date>
    </item>
    <item>
      <title>Re: want to understand some code writing</title>
      <link>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483756#M125498</link>
      <description>&lt;P&gt;No, visitnum=. does nothing here.&amp;nbsp; If the program is actually more complex, and contains additional statements that you have removed, then it may serve a purpose.&lt;/P&gt;</description>
      <pubDate>Fri, 03 Aug 2018 13:05:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/want-to-understand-some-code-writing/m-p/483756#M125498</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-08-03T13:05:07Z</dc:date>
    </item>
  </channel>
</rss>

