<?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 From Stata to SAS Code in Statistical Procedures</title>
    <link>https://communities.sas.com/t5/Statistical-Procedures/From-Stata-to-SAS-Code/m-p/416040#M21828</link>
    <description>&lt;P&gt;Hello Friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not STATA user. I tried to understand this language so I could translate its code into SAS. I need your input in certifying that my SAS code is equivalent to the Stata code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Example STATA code:*/&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;gen strataid=.&lt;BR /&gt;replace strataid=(GESTFIPS*10000)+ HG_MSAC if HG_MSAC &amp;gt; 0&lt;BR /&gt;replace strataid =(GESTFIPS*1000) + GECO if GECO &amp;gt; 0 &amp;amp; HG_MSAC==0&lt;BR /&gt;replace strataid = GESTFIPS if GECO == 0 &amp;amp; HG_MSAC == 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I converted the above code into SAS:&lt;BR /&gt;................................;&lt;BR /&gt;length STRATAID 4;&lt;BR /&gt;set stratumxplr;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;if missing(GECO) then call missing (STRATAID);&lt;BR /&gt;&amp;nbsp;if missing (HG_MSAC) then call missing (STRATAID);&lt;BR /&gt;&amp;nbsp;if missing (GESTFIPS) then call missing (STRATAID);&lt;BR /&gt;&amp;nbsp;if GTCBSA &amp;gt; 0 then STRATAID = (GESTFIPS*10000) + GTCBSA;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if GTCO &amp;gt; 0 and GTCBSA = 0 then STRATAID = (GESTFIPS*1000) + GTCO;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if GTCO = 0 and GTCBSA = 0 then STRATAID = GESTFIPS;&lt;BR /&gt;&amp;nbsp;label STRATAID = 'Stratum Identification';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Are the Stata double == equal signs equivalent to SAS one equal sign?&lt;/P&gt;&lt;P&gt;Stata code is from Michael Davern et al. p. 14 (&lt;A href="http://journals.sagepub.com/doi/pdf/10.5034/inquiryjrnl_43.3.283" target="_blank"&gt;http://journals.sagepub.com/doi/pdf/10.5034/inquiryjrnl_43.3.283&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Artp&lt;/P&gt;&lt;P&gt;====&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 24 Nov 2017 15:18:24 GMT</pubDate>
    <dc:creator>Artp</dc:creator>
    <dc:date>2017-11-24T15:18:24Z</dc:date>
    <item>
      <title>From Stata to SAS Code</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/From-Stata-to-SAS-Code/m-p/416040#M21828</link>
      <description>&lt;P&gt;Hello Friends,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not STATA user. I tried to understand this language so I could translate its code into SAS. I need your input in certifying that my SAS code is equivalent to the Stata code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/*Example STATA code:*/&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;gen strataid=.&lt;BR /&gt;replace strataid=(GESTFIPS*10000)+ HG_MSAC if HG_MSAC &amp;gt; 0&lt;BR /&gt;replace strataid =(GESTFIPS*1000) + GECO if GECO &amp;gt; 0 &amp;amp; HG_MSAC==0&lt;BR /&gt;replace strataid = GESTFIPS if GECO == 0 &amp;amp; HG_MSAC == 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is how I converted the above code into SAS:&lt;BR /&gt;................................;&lt;BR /&gt;length STRATAID 4;&lt;BR /&gt;set stratumxplr;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;&lt;BR /&gt;&amp;nbsp;if missing(GECO) then call missing (STRATAID);&lt;BR /&gt;&amp;nbsp;if missing (HG_MSAC) then call missing (STRATAID);&lt;BR /&gt;&amp;nbsp;if missing (GESTFIPS) then call missing (STRATAID);&lt;BR /&gt;&amp;nbsp;if GTCBSA &amp;gt; 0 then STRATAID = (GESTFIPS*10000) + GTCBSA;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if GTCO &amp;gt; 0 and GTCBSA = 0 then STRATAID = (GESTFIPS*1000) + GTCO;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else if GTCO = 0 and GTCBSA = 0 then STRATAID = GESTFIPS;&lt;BR /&gt;&amp;nbsp;label STRATAID = 'Stratum Identification';&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;Are the Stata double == equal signs equivalent to SAS one equal sign?&lt;/P&gt;&lt;P&gt;Stata code is from Michael Davern et al. p. 14 (&lt;A href="http://journals.sagepub.com/doi/pdf/10.5034/inquiryjrnl_43.3.283" target="_blank"&gt;http://journals.sagepub.com/doi/pdf/10.5034/inquiryjrnl_43.3.283&lt;/A&gt;).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your help,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Artp&lt;/P&gt;&lt;P&gt;====&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 15:18:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/From-Stata-to-SAS-Code/m-p/416040#M21828</guid>
      <dc:creator>Artp</dc:creator>
      <dc:date>2017-11-24T15:18:24Z</dc:date>
    </item>
    <item>
      <title>Re: From Stata to SAS Code</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/From-Stata-to-SAS-Code/m-p/416085#M21834</link>
      <description>&lt;P&gt;If stata follows C rules (likely), == is the comparison operator, while = assigns values. In SAS, both are done with a single =.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 20:48:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/From-Stata-to-SAS-Code/m-p/416085#M21834</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-24T20:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: From Stata to SAS Code</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/From-Stata-to-SAS-Code/m-p/416086#M21835</link>
      <description>&lt;P&gt;PS for final verification, practice beats theory: run both codes in their respective environments and compare the results.&lt;/P&gt;</description>
      <pubDate>Fri, 24 Nov 2017 20:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/From-Stata-to-SAS-Code/m-p/416086#M21835</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-24T20:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: From Stata to SAS Code</title>
      <link>https://communities.sas.com/t5/Statistical-Procedures/From-Stata-to-SAS-Code/m-p/416114#M21837</link>
      <description>&lt;P&gt;It looks like the STATA code is unconditionally initiating the new variable to missing.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It does not look like the STATA code is using anything that is the equivalent of the ELSE statements in your code.&amp;nbsp; But since the conditions look to be mutually exclusive it shouldn't matter.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why did use set the LENGTH of your new variable to 4?&amp;nbsp; SAS uses 64bit floating point numbers for all numeric variables. Storing only 4 of the 8 bytes will potentially remove some of the precision of the values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In SAS equality testing is done with a single equal sign. Or the EQ keyword.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Nov 2017 04:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/Statistical-Procedures/From-Stata-to-SAS-Code/m-p/416114#M21837</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-11-25T04:27:42Z</dc:date>
    </item>
  </channel>
</rss>

