<?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: way to simplyfy the code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/way-to-simplify-the-code/m-p/447538#M112450</link>
    <description>&lt;P&gt;You're creating your groups based on the &lt;SPAN&gt;dirsection variable, except you're making it capital?&lt;/SPAN&gt;&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;PRE&gt;&lt;CODE class=" language-sas"&gt;if compno in ('02','34') and lobcod in ('FDA','SHP') and dirsection='NP' then do; ptype='NP'; output NP; end;
if compno in ('02','34') and lobcod in ('FDA','SHP') and dirsection='ADHS' then do; ptype='ADHS'; output ADHS; end;
if compno in ('02','34') and lobcod in ('FDA','SHP') and dirsection='aadh' then do; ptype='AADH'; output AADH; end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is the same as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if compno in ('02','34') and lobcod in ('FDA','SHP') then ptype=upcase(dirsection);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once that's sorted out, you can use any of the methods illustrated here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, one big caveat, in general this is not a good way to store data in SAS. If you're trying to separate data for analysis or for exporting to separate files there are other, better, ways.&lt;/P&gt;</description>
    <pubDate>Wed, 21 Mar 2018 19:03:40 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2018-03-21T19:03:40Z</dc:date>
    <item>
      <title>way to simplify the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/way-to-simplify-the-code/m-p/447535#M112448</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have a dataset A and need to create multiple datasets based on the compno ,lobcod and dirsection values.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to simplify the below steps instead of creating multiple lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; compno in (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'02'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'34'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) and lobcod in (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'FDA'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'SHP'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) and dirsection=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'NP'&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;then&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; ptype=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'NP'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; NP; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; compno in (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'02'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'34'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) and lobcod in (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'FDA'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'SHP'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) and dirsection=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'ADHS'&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;then&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; ptype=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'ADHS'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; ADHS; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; compno in (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'02'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'34'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) and lobcod in (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'FDA'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'SHP'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) and dirsection=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'aadh'&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;then&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; ptype=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'AADH'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; AADH; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2"&gt;Thanks in Advance.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;if&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; compno in (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'02'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'34'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) and lobcod in (&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'FDA'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'SHP'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;) and dirsection=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'CDPAS'&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;then&lt;/FONT&gt; &lt;FONT face="Courier New" size="2" color="#0000ff"&gt;do&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; ptype=&lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#800080"&gt;'CDPAS'&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;output&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt; CDPAS; &lt;/FONT&gt;&lt;FONT face="Courier New" size="2" color="#0000ff"&gt;end&lt;/FONT&gt;&lt;FONT face="Courier New" size="2"&gt;; &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 19:42:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/way-to-simplify-the-code/m-p/447535#M112448</guid>
      <dc:creator>cho16</dc:creator>
      <dc:date>2018-03-22T19:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: way to simplyfy the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/way-to-simplify-the-code/m-p/447538#M112450</link>
      <description>&lt;P&gt;You're creating your groups based on the &lt;SPAN&gt;dirsection variable, except you're making it capital?&lt;/SPAN&gt;&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;PRE&gt;&lt;CODE class=" language-sas"&gt;if compno in ('02','34') and lobcod in ('FDA','SHP') and dirsection='NP' then do; ptype='NP'; output NP; end;
if compno in ('02','34') and lobcod in ('FDA','SHP') and dirsection='ADHS' then do; ptype='ADHS'; output ADHS; end;
if compno in ('02','34') and lobcod in ('FDA','SHP') and dirsection='aadh' then do; ptype='AADH'; output AADH; end;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;is the same as:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if compno in ('02','34') and lobcod in ('FDA','SHP') then ptype=upcase(dirsection);

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Once that's sorted out, you can use any of the methods illustrated here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/" target="_blank"&gt;https://blogs.sas.com/content/sasdummy/2015/01/26/how-to-split-one-data-set-into-many/&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But, one big caveat, in general this is not a good way to store data in SAS. If you're trying to separate data for analysis or for exporting to separate files there are other, better, ways.&lt;/P&gt;</description>
      <pubDate>Wed, 21 Mar 2018 19:03:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/way-to-simplify-the-code/m-p/447538#M112450</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-03-21T19:03:40Z</dc:date>
    </item>
    <item>
      <title>Re: way to simplyfy the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/way-to-simplify-the-code/m-p/447544#M112453</link>
      <description>&lt;P&gt;If your trying to output all distinct&amp;nbsp;&lt;SPAN&gt;dirsection into separate individual datasets then something like this works.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct dirsection into:dirsection separated by " "
	from have;
quit;

data &amp;amp;dirsection ;
set have;
do i=1 to countw(&amp;amp;dirsection);
%let Val=scan(&amp;amp;dirsection,i);
if compno in ('02','34') and lobcod in ('FDA','SHP') and upcase(dirsection)=upcase("&amp;amp;val") 
		then do;
			ptype=dirsection;
			output &amp;amp;Val;
			end;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 21 Mar 2018 19:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/way-to-simplify-the-code/m-p/447544#M112453</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-21T19:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: way to simplyfy the code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/way-to-simplify-the-code/m-p/447902#M112598</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/34445"&gt;@MarkWik&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078" target="_blank"&gt;@SuryaKiran&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp; Your proposed solution on the thread&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/way-to-simplyfy-the-code/m-p/447544#M112453%C2%A0" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/way-to-simplyfy-the-code/m-p/447544#M112453&amp;nbsp;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;doesn't work either as you have gotten the macro execution and sas execution comepletely wrong. I don't want mean to sound strong/harsh but I have to concur with&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/144199" target="_blank"&gt;@tomrvincent&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp; in the objective that it may mislead for the OP and other readers&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/83078"&gt;@SuryaKiran&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;If your trying to output all distinct&amp;nbsp;&lt;SPAN&gt;dirsection into separate individual datasets then something like this works.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
select distinct dirsection into:dirsection separated by " "
	from have;
quit;

data "&amp;amp;dirsection" ;
set have;
do i=1 to countw("&amp;amp;dirsection");
%let Val=scan("&amp;amp;dirsection",i);
if compno in ('02','34') and lobcod in ('FDA','SHP') and upcase(dirsection)=upcase("&amp;amp;val") 
		then do;
			ptype=dirsection;
			output &amp;amp;Val;
			end;
end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;BR /&gt;I agree with you, I just gave an approach to handle and didn't test because I don't have sample data or time. Thanks for pointing out.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 22 Mar 2018 19:33:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/way-to-simplify-the-code/m-p/447902#M112598</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-22T19:33:18Z</dc:date>
    </item>
  </channel>
</rss>

