<?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: IS the below code correct  ?? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IS-the-below-code-correct/m-p/736905#M229680</link>
    <description>&lt;P&gt;It is hardly possible to answer the question without seeing the data. But your code has some issues:&lt;/P&gt;
&lt;P&gt;1. It is almost always a bad idea to overwrite the dataset being processed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subject;
  set subjects;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. No length-statement for the new variable "second_major".&lt;/P&gt;
&lt;P&gt;3. Using count will cause unexpected results, because&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count("sand", "and") &amp;gt; 0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using findw is better.&lt;/P&gt;
&lt;P&gt;4. Remove&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if count(major,'&amp;amp;')&amp;gt;0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and move both assignment statements into the first if-statement.&lt;/P&gt;</description>
    <pubDate>Mon, 26 Apr 2021 05:21:00 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-04-26T05:21:00Z</dc:date>
    <item>
      <title>IS the below code correct  ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IS-the-below-code-correct/m-p/736898#M229674</link>
      <description>&lt;P&gt;/* inspect the variable major .The variable major should contain only one major for ex:physics or science&lt;BR /&gt;.some observations has two majors listed in this variable seperated by the word "and"(always in low case),such as maths and social&lt;BR /&gt;. use the word and to identify the a second major and if founf put the second major in a new variable named second_major&lt;BR /&gt;.when they are two majors the original major should be modified so that it contains only first major . What is the ffrequency of variable major*/&lt;BR /&gt;data subject;&lt;BR /&gt;set subjects;&lt;BR /&gt;if count(major,'and')&amp;gt;0 then do;&lt;BR /&gt;major=tranwrd(major,'and','&amp;amp;');&lt;BR /&gt;end;&lt;BR /&gt;if count(major,'&amp;amp;')&amp;gt;0 then second_major=scan(major,2,'&amp;amp;');&lt;BR /&gt;if count(major,'&amp;amp;')&amp;gt;0 or count(major,'&amp;amp;')=0 then major=scan(strip(major),1,'&amp;amp;');&lt;BR /&gt;run;&lt;BR /&gt;proc freq data=subject;&lt;BR /&gt;table major;&lt;BR /&gt;run;&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;&lt;P&gt;&amp;nbsp;&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV class="dijitContentPane dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignCenter dijitContentPaneSingleChild"&gt;&lt;DIV class="dijitBorderContainer dijitContainer row-fluid dijitLayoutContainer"&gt;&lt;DIV class="dijitContentPane dijitAlignCenter dijitContentPaneSingleChild dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane"&gt;&lt;DIV class="tabs dijitBorderContainer dijitContainer dojoDndTarget sasStudioTabsParentContainer dijitLayoutContainer dojoDndContainerOver"&gt;&lt;DIV class="dijitTabContainer dijitTabContainerTop dijitContainer dijitLayoutContainer tabStrip-disabled sasStudioTabsTabContainer sasStudioTabsTabContainerVertical sasStudioTabsTop dijitBorderContainer-child dijitBorderContainer-dijitTabContainerTop dijitBorderContainerPane dijitAlignCenter"&gt;&lt;DIV class="dijitTabPaneWrapper dijitTabContainerTop-container dijitAlignCenter"&gt;&lt;DIV class="dijitTabContainerTopChildWrapper dijitVisible"&gt;&lt;DIV class="dijitBorderContainer dijitContainer sasStudioTabsTabContainerChild dijitTabPane dijitTabContainerTop-child dijitTabContainerTop-dijitBorderContainer dijitLayoutContainer"&gt;&lt;DIV class="dijitContentPane dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignCenter dijitContentPaneSingleChild"&gt;&lt;DIV class="dijitBorderContainer dijitContainer dijitLayoutContainer"&gt;&lt;DIV class="dijitContentPane dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignCenter dijitContentPaneSingleChild"&gt;&lt;DIV class="dijitBorderContainer dijitContainer dijitLayoutContainer"&gt;&lt;DIV class="dijitContentPane dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignCenter dijitContentPaneSingleChild"&gt;&lt;DIV class="dgrid dgrid-grid ui-widget"&gt;&lt;DIV class="dgrid-header dgrid-header-scroll dgrid-scrollbar-width ui-widget-header"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV class="dijitContentPane statusBar dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignBottom"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="dijitContentPane statusBar dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignBottom"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="dijitContentPane statusBar dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignBottom"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class="dijitContentPane statusBar dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignBottom"&gt;&lt;DIV class="dijitContentPane statusBar dijitBorderContainer-child dijitBorderContainer-dijitContentPane dijitBorderContainerPane dijitAlignBottom"&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Mon, 26 Apr 2021 02:07:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IS-the-below-code-correct/m-p/736898#M229674</guid>
      <dc:creator>username12</dc:creator>
      <dc:date>2021-04-26T02:07:49Z</dc:date>
    </item>
    <item>
      <title>Re: IS the below code correct  ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IS-the-below-code-correct/m-p/736899#M229675</link>
      <description>&lt;P&gt;Without seeing the data, it is difficult to say for sure, but for now,&lt;/P&gt;
&lt;P&gt;neither the tranwrd nor the scan function will cause an error even if the target is not found, so the following should be fine.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subject;
  set subjects;
  major=tranwrd(major,'and','&amp;amp;');
  second_major=scan(major,2,'&amp;amp;');
  major=scan(major,1,'&amp;amp;');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 26 Apr 2021 02:42:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IS-the-below-code-correct/m-p/736899#M229675</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-04-26T02:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: IS the below code correct  ??</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IS-the-below-code-correct/m-p/736905#M229680</link>
      <description>&lt;P&gt;It is hardly possible to answer the question without seeing the data. But your code has some issues:&lt;/P&gt;
&lt;P&gt;1. It is almost always a bad idea to overwrite the dataset being processed.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subject;
  set subjects;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;2. No length-statement for the new variable "second_major".&lt;/P&gt;
&lt;P&gt;3. Using count will cause unexpected results, because&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;count("sand", "and") &amp;gt; 0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Using findw is better.&lt;/P&gt;
&lt;P&gt;4. Remove&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if count(major,'&amp;amp;')&amp;gt;0&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and move both assignment statements into the first if-statement.&lt;/P&gt;</description>
      <pubDate>Mon, 26 Apr 2021 05:21:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IS-the-below-code-correct/m-p/736905#M229680</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-04-26T05:21:00Z</dc:date>
    </item>
  </channel>
</rss>

