<?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: compact SAS code in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316765#M61740</link>
    <description>&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; array yn {26} a -- z; &amp;nbsp;/* better rename A-Z into q1-q26 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;check = 'N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; do i=1 to dim(yn);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if yn(i) = 'Y' then check = 'Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
    <pubDate>Mon, 05 Dec 2016 16:37:32 GMT</pubDate>
    <dc:creator>Shmuel</dc:creator>
    <dc:date>2016-12-05T16:37:32Z</dc:date>
    <item>
      <title>compact SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316761#M61739</link>
      <description>&lt;P&gt;I have variables A-Z. Values for A-Z (26 variables) are "Y" "N". &amp;nbsp;I want to create a new variable CHECK based on A-Z. If all A-Z (26 variables) ="N", then CHECK would be "N". How can I write a short/clean code to do so instead using code like the following?&amp;nbsp;&lt;/P&gt;&lt;P&gt;if A="N" and B&lt;SPAN&gt;="N" and C ="N" and D ="N" and E="N"......and Z="N" then CHECK="N"&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Is there a short cut for above redundant code?&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;thanks.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Xiaoyi&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:27:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316761#M61739</guid>
      <dc:creator>Xiaoyi</dc:creator>
      <dc:date>2016-12-05T16:27:03Z</dc:date>
    </item>
    <item>
      <title>Re: compact SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316765#M61740</link>
      <description>&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; array yn {26} a -- z; &amp;nbsp;/* better rename A-Z into q1-q26 */&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;check = 'N';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; do i=1 to dim(yn);&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if yn(i) = 'Y' then check = 'Y';&lt;/P&gt;
&lt;P&gt;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:37:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316765#M61740</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2016-12-05T16:37:32Z</dc:date>
    </item>
    <item>
      <title>Re: compact SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316766#M61741</link>
      <description>&lt;P&gt;Are you sure every variables is either N or Y. &amp;nbsp;That is there are no blank variables?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if whichc('Y', of A b C d E f G h I j K l M n O p Q r S t U v W x Y z) then check='Y';
else check='N';
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It would be even easier if you know that all 26 varaibles as next to each other in the data vector. Then you could use variable list like A--Z instead of having to type all 26 variable names.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could also look at using CATS() function to generate the 26 character string that has all of the value and then test that.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:37:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316766#M61741</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-05T16:37:09Z</dc:date>
    </item>
    <item>
      <title>Re: compact SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316767#M61742</link>
      <description>&lt;P&gt;If your variables are created in sequence so that this list specifies the exact right set of variables, then the problem becomes easy.&amp;nbsp; The list:&amp;nbsp; A--Z&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can check this in various ways (PROC CONTENTS will print the order in which the variables were created, or you can try a PROC PRINT with the VAR statement VAR A--Z).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;At any rate, if the variables are in the proper sequence, this would work:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if cats(of A--Z) = repeat("N", 25) then check="N";&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:37:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316767#M61742</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-05T16:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: compact SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316773#M61744</link>
      <description>&lt;P&gt;Are there other values desired for Check? Under which conditions?&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 16:50:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316773#M61744</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-12-05T16:50:51Z</dc:date>
    </item>
    <item>
      <title>Re: compact SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316781#M61746</link>
      <description>&lt;P&gt;Thanks for the quick response.&amp;nbsp;&lt;/P&gt;&lt;P&gt;if any of the A-Z variables is "Y" then CHECK is "Yes",&amp;nbsp;&lt;/P&gt;&lt;P&gt;if all the of A-Z variables is "N" then CHECK &amp;nbsp;is "No",&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the rest CHECK is "Unknown", &amp;nbsp;I am trying to find an easier way to code it. Any suggestions? also I realize that when I define CHECK="Yes", the length was set, so "Unknown" showed up as "Unk". Any suggestion to fix the length?&lt;/P&gt;&lt;P&gt;Thanks again.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Xiaoyi&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 17:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316781#M61746</guid>
      <dc:creator>Xiaoyi</dc:creator>
      <dc:date>2016-12-05T17:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: compact SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316785#M61747</link>
      <description>&lt;P&gt;I think what you are asking for is this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;length check $ 7;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just include that in the DATA step before the IF/THEN statements that assign values to CHECK.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 17:19:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316785#M61747</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-12-05T17:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: compact SAS code</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316788#M61748</link>
      <description>&lt;P&gt;If you don't want SAS to guess how long to make your variable then define it before you reference it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;length check $7 ;
if index(cats(of A -- Z),'Y') then check='Yes';
else if repeat('N',26-1) = cats(of A -- Z) then check='No';
else check = 'Unknown';
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Dec 2016 17:24:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/compact-SAS-code/m-p/316788#M61748</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-12-05T17:24:14Z</dc:date>
    </item>
  </channel>
</rss>

