<?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 SAS set statement and if clause in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-set-statement-and-if-clause/m-p/466509#M119033</link>
    <description>&lt;P&gt;data central;&lt;BR /&gt;input patient visit datatype $;&lt;BR /&gt;cards;&lt;BR /&gt;1 10 cenrtal&lt;BR /&gt;1 11 cenrtal&lt;BR /&gt;1 12 cenrtal&lt;BR /&gt;2 13 cenrtal&lt;BR /&gt;2 14 cenrtal&lt;BR /&gt;2 15 cenrtal&lt;BR /&gt;3 16 cenrtal&lt;BR /&gt;3 17 cenrtal&lt;BR /&gt;3 18 cenrtal&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data local;&lt;BR /&gt;input patient studyday datatype $;&lt;BR /&gt;cards;&lt;BR /&gt;1 100 local&lt;BR /&gt;1 121 local&lt;BR /&gt;1 144 local&lt;BR /&gt;2 169 local&lt;BR /&gt;2 196 local&lt;BR /&gt;2 225 local&lt;BR /&gt;3 256 local&lt;BR /&gt;3 289 local&lt;BR /&gt;3 324 local&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data all1;&lt;BR /&gt;set local central;&lt;BR /&gt;if visit=. then visit=sqrt(studyday);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data all;&lt;BR /&gt;set local central;&lt;BR /&gt;run;&lt;BR /&gt;data all2;&lt;BR /&gt;set all;&lt;BR /&gt;if visit=. then visit=sqrt(studyday);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me? Why the results of all1 and all2 are different? Why in data all1 the visit variable automate retain while in all2 not?&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 31 May 2018 15:17:50 GMT</pubDate>
    <dc:creator>jeremyyjm</dc:creator>
    <dc:date>2018-05-31T15:17:50Z</dc:date>
    <item>
      <title>SAS set statement and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-set-statement-and-if-clause/m-p/466509#M119033</link>
      <description>&lt;P&gt;data central;&lt;BR /&gt;input patient visit datatype $;&lt;BR /&gt;cards;&lt;BR /&gt;1 10 cenrtal&lt;BR /&gt;1 11 cenrtal&lt;BR /&gt;1 12 cenrtal&lt;BR /&gt;2 13 cenrtal&lt;BR /&gt;2 14 cenrtal&lt;BR /&gt;2 15 cenrtal&lt;BR /&gt;3 16 cenrtal&lt;BR /&gt;3 17 cenrtal&lt;BR /&gt;3 18 cenrtal&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;data local;&lt;BR /&gt;input patient studyday datatype $;&lt;BR /&gt;cards;&lt;BR /&gt;1 100 local&lt;BR /&gt;1 121 local&lt;BR /&gt;1 144 local&lt;BR /&gt;2 169 local&lt;BR /&gt;2 196 local&lt;BR /&gt;2 225 local&lt;BR /&gt;3 256 local&lt;BR /&gt;3 289 local&lt;BR /&gt;3 324 local&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data all1;&lt;BR /&gt;set local central;&lt;BR /&gt;if visit=. then visit=sqrt(studyday);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;data all;&lt;BR /&gt;set local central;&lt;BR /&gt;run;&lt;BR /&gt;data all2;&lt;BR /&gt;set all;&lt;BR /&gt;if visit=. then visit=sqrt(studyday);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone help me? Why the results of all1 and all2 are different? Why in data all1 the visit variable automate retain while in all2 not?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 15:17:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-set-statement-and-if-clause/m-p/466509#M119033</guid>
      <dc:creator>jeremyyjm</dc:creator>
      <dc:date>2018-05-31T15:17:50Z</dc:date>
    </item>
    <item>
      <title>Re: SAS set statement and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-set-statement-and-if-clause/m-p/466530#M119046</link>
      <description>&lt;P&gt;Great question!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any variable that comes from a SAS data set is automatically retained.&amp;nbsp; With that in mind, consider what happens on the second observation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When constructing ALL1, VISIT does come from a SAS data set.&amp;nbsp; So its value is retained.&amp;nbsp; On the first observation, VISIT got calculated as being 10.&amp;nbsp; So on the second observation, that value is retained.&amp;nbsp; Since VISIT is not missing, it does not get recalculated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When constructing ALL2, again VISIT comes from a SAS data set.&amp;nbsp; So again its value is retained.&amp;nbsp; However, in the process of constructing the data set ALL, VISIT became part of &lt;STRONG&gt;every&lt;/STRONG&gt; observation in ALL.&amp;nbsp; (It has a missing value for those observations that came from LOCAL.)&amp;nbsp; On the first observation, VISIT gets calculated as being 10.&amp;nbsp; On the second observation, the result is a little different (as you have seen).&amp;nbsp; The SET statement reads in the second observation from ALL, where VISIT has a missing value.&amp;nbsp; That missing value overwrites the retained value of 10.&amp;nbsp; So VISIT is now missing and the IF THEN condition is true.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might help to add PUT statements before the SET statement, after the SET statement, and after the IF THEN statement to examine the value of VISIT at each point along the way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 16:00:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-set-statement-and-if-clause/m-p/466530#M119046</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-05-31T16:00:54Z</dc:date>
    </item>
    <item>
      <title>Re: SAS set statement and if clause</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-set-statement-and-if-clause/m-p/466569#M119052</link>
      <description>&lt;P&gt;Thanks, Astounding, great explanation.&lt;/P&gt;</description>
      <pubDate>Thu, 31 May 2018 17:58:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-set-statement-and-if-clause/m-p/466569#M119052</guid>
      <dc:creator>jeremyyjm</dc:creator>
      <dc:date>2018-05-31T17:58:36Z</dc:date>
    </item>
  </channel>
</rss>

