<?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: shortening program.... in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34026#M8262</link>
    <description>You can use Peter's test and the fact that sas can do character loops (in data steps at least, if not in macros):&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data sample;&lt;BR /&gt;
  input cpt1 $ cpt2 $ cpt3 $ cpt4 $ cpt5$;&lt;BR /&gt;
  do i='D9110','D9310','D9610';&lt;BR /&gt;
    ags + ^^( FIND( catx( '#', of cpt1-cpt5  ), i ) );&lt;BR /&gt;
  end;&lt;BR /&gt;
  put ags=;&lt;BR /&gt;
cards;&lt;BR /&gt;
D9110 1100 122 2000 D9110 &lt;BR /&gt;
200 D9610 140 D9110 D9310 &lt;BR /&gt;
3000 D9110 D9230 300 D9110 &lt;BR /&gt;
D9610 3000 7777 7889 D9310 &lt;BR /&gt;
D9110 2333 3333 666 D9610 &lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
This way you have all in one place:&lt;BR /&gt;
- a single list for all test values (in the loop)&lt;BR /&gt;
- a single list for all test variables (in the concatenation list)&lt;BR /&gt;
and you can massage the sums or derive ratios any way you want in the data step.</description>
    <pubDate>Wed, 27 May 2009 22:24:55 GMT</pubDate>
    <dc:creator>ChrisNZ</dc:creator>
    <dc:date>2009-05-27T22:24:55Z</dc:date>
    <item>
      <title>shortening program....</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34020#M8256</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I wanted to make my program shorter this is the text that I have, I could I use a do loop and make it shorter.  Thanks.&lt;BR /&gt;
Essentially what I am trying to do is to read in five fields across cpt1 - cpt5 and if the following character variable is there in any of those five fields then it should be coded as one, else it should be zero.  &lt;BR /&gt;
&lt;BR /&gt;
Then I need to add up where all the variables that are coded equal one.  where ags = 1 and ags1 = 1 and ags2 = 1 and ags3 = 1, because I want to add up all the number of times that variable equals 1.  I only want frequencies and percentages.&lt;BR /&gt;
&lt;BR /&gt;
Thank you!&lt;BR /&gt;
&lt;BR /&gt;
If ( cpt1 = 'D9110' or cpt2 = 'D9110' or cpt3 = 'D9110' or cpt4 = 'D9110'&lt;BR /&gt;
or cpt5 = 'D9110') then ags = 1; else ags = 0;&lt;BR /&gt;
&lt;BR /&gt;
If ( cpt1 = 'D9230' or cpt2 = 'D9230' or cpt3 = 'D9230' or cpt4 = 'D9230'&lt;BR /&gt;
or cpt5 = 'D9230') then ags1= 1; else ags1 = 0;&lt;BR /&gt;
&lt;BR /&gt;
If ( cpt1 = 'D9310' or cpt2 = 'D9310' or cpt3 = 'D9310' or cpt4 = 'D9310'&lt;BR /&gt;
or cpt5 = 'D9310') then ags2 = 1; else ags2 = 0;&lt;BR /&gt;
&lt;BR /&gt;
If ( cpt1 = 'D9610' or cpt2 = 'D9610' or cpt3 = 'D9610' or cpt4 = 'D9610'&lt;BR /&gt;
or cpt5 = 'D9610') then ags3 = 1; else ags3 = 0;</description>
      <pubDate>Tue, 19 May 2009 22:22:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34020#M8256</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-19T22:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: shortening program....</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34021#M8257</link>
      <description>This is a perfect application for ARRAYs.  See your own question/posting from two weeks ago&lt;BR /&gt;
&lt;A href="http://support.sas.com/forums/message.jspa?messageID=20617#20617" target="_blank"&gt;http://support.sas.com/forums/message.jspa?messageID=20617#20617&lt;/A&gt;</description>
      <pubDate>Wed, 20 May 2009 13:43:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34021#M8257</guid>
      <dc:creator>Doc_Duke</dc:creator>
      <dc:date>2009-05-20T13:43:55Z</dc:date>
    </item>
    <item>
      <title>Re: shortening program....</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34022#M8258</link>
      <description>Not sure whether I have understood your problem correctly. I Have tried the following code: This will calculate number of times those variables are "1" and Percentages acorss each observation and across overall observations. &lt;BR /&gt;
&lt;BR /&gt;
data sample;&lt;BR /&gt;
    input cpt1 $ cpt2 $ cpt3 $ cpt4 $ cpt5$;&lt;BR /&gt;
	cards;&lt;BR /&gt;
	D9110 1100 122 2000 D9110 &lt;BR /&gt;
	200 D9610 140 D9110 D9310 &lt;BR /&gt;
                3000 D9110 D9230 300 D9110 &lt;BR /&gt;
                D9610  3000 7777 7889 D9310 &lt;BR /&gt;
                D9110  2333 3333 666 D9610 &lt;BR /&gt;
    ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data sample1;&lt;BR /&gt;
  set sample nobs=totobs;&lt;BR /&gt;
  array cpt{5} $20 cpt1-cpt5;&lt;BR /&gt;
  do i=1 to 5;&lt;BR /&gt;
  	if cpt(i)='D9110' then do; ags=1; count+1; end; else ags=0;&lt;BR /&gt;
  	if cpt(i)='D9230' then do; ags1=1; count+1; end; else ags1=0;&lt;BR /&gt;
  	if cpt(i)='D9310' then do; ags2=1; count+1; end; else ags2=0;&lt;BR /&gt;
  	if cpt(i)='D9610' then do; ags3=1; count+1; end; else ags3=0;&lt;BR /&gt;
  end;&lt;BR /&gt;
  percent=(count/(totobs*5)*100)||"%";&lt;BR /&gt;
  put _ALL_;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
~Sukanya E

~Sukanya E&lt;BR /&gt;
&lt;BR /&gt;
    &lt;BR /&gt;
Message was edited by: Sukanya</description>
      <pubDate>Wed, 20 May 2009 21:16:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34022#M8258</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-20T21:16:07Z</dc:date>
    </item>
    <item>
      <title>Re: shortening program....</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34023#M8259</link>
      <description>Also you may want to explore the use of a hash table to load up the list of values to check for, further reducing the SAS program while simplifying the maintenance of your look-up values list.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.&lt;BR /&gt;
&lt;BR /&gt;
Using the Hash Object&lt;BR /&gt;
&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002585310.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/61722/HTML/default/a002585310.htm&lt;/A&gt;</description>
      <pubDate>Wed, 20 May 2009 21:28:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34023#M8259</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-05-20T21:28:06Z</dc:date>
    </item>
    <item>
      <title>Re: shortening program....</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34024#M8260</link>
      <description>it would have been helpful if this were possible[pre]   if 'D9110' in( cpt1,cpt2,cpt3,cpt4,cpt5 ) then ags= 1; else ags=0 ;[/pre]however, the in() function expects a list of constants and rejects variables.&lt;BR /&gt;
Without using hash tables or arrays, one alternative gets IF to search a concatenation of the variables, like:[pre]      ags = ^^( FIND( catx( '#', of cpt1-cpt5  ), 'D9110' )) ;&lt;BR /&gt;
      ags1= ^^( FIND( catx( '#', of cpt1-cpt5  ), 'D9230' )) ;&lt;BR /&gt;
      ags2= ^^( FIND( catx( '#', of cpt1-cpt5  ), 'D9310' )) ;&lt;BR /&gt;
      ags3= ^^( FIND( catx( '#', of cpt1-cpt5  ), 'D9610' )) ;[/pre]&lt;BR /&gt;
This returns a 1/0 for ags if D9110 is in any of those columns CPT1-5, ags1 for D9230, ags2 for D9310, etc.&lt;BR /&gt;
 &lt;BR /&gt;
I've tested it  and it worked&lt;BR /&gt;
 &lt;BR /&gt;
if you need a more generalised approach, please provide some more detail. &lt;BR /&gt;
 &lt;BR /&gt;
does this help?&lt;BR /&gt;
 &lt;BR /&gt;
PeterC</description>
      <pubDate>Thu, 21 May 2009 14:47:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34024#M8260</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2009-05-21T14:47:07Z</dc:date>
    </item>
    <item>
      <title>Re: shortening program....</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34025#M8261</link>
      <description>Taking advantage of SAS boolean behavior of returning 1 for true and 0 for false:&lt;BR /&gt;
&lt;BR /&gt;
ags =( cpt1 = 'D9110' ) + ( cpt2 = 'D9110' ) + (  cpt3 = 'D9110' ) + (  cpt4 = 'D9110') + ( cpt5 = 'D9110');&lt;BR /&gt;
&lt;BR /&gt;
By extension a total count could be generated by including all of the pairs of variable and value if desired. This is not intuitively obvious and should be documented when using this trick for those that haven't seen it. This sometimes runs a bit faster than lots of explicit if-then statements as well.</description>
      <pubDate>Wed, 27 May 2009 21:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34025#M8261</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2009-05-27T21:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: shortening program....</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34026#M8262</link>
      <description>You can use Peter's test and the fact that sas can do character loops (in data steps at least, if not in macros):&lt;BR /&gt;
&lt;BR /&gt;
[pre]&lt;BR /&gt;
data sample;&lt;BR /&gt;
  input cpt1 $ cpt2 $ cpt3 $ cpt4 $ cpt5$;&lt;BR /&gt;
  do i='D9110','D9310','D9610';&lt;BR /&gt;
    ags + ^^( FIND( catx( '#', of cpt1-cpt5  ), i ) );&lt;BR /&gt;
  end;&lt;BR /&gt;
  put ags=;&lt;BR /&gt;
cards;&lt;BR /&gt;
D9110 1100 122 2000 D9110 &lt;BR /&gt;
200 D9610 140 D9110 D9310 &lt;BR /&gt;
3000 D9110 D9230 300 D9110 &lt;BR /&gt;
D9610 3000 7777 7889 D9310 &lt;BR /&gt;
D9110 2333 3333 666 D9610 &lt;BR /&gt;
run;&lt;BR /&gt;
[/pre]&lt;BR /&gt;
&lt;BR /&gt;
This way you have all in one place:&lt;BR /&gt;
- a single list for all test values (in the loop)&lt;BR /&gt;
- a single list for all test variables (in the concatenation list)&lt;BR /&gt;
and you can massage the sums or derive ratios any way you want in the data step.</description>
      <pubDate>Wed, 27 May 2009 22:24:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34026#M8262</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-05-27T22:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: shortening program....</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34027#M8263</link>
      <description>it worked</description>
      <pubDate>Thu, 28 May 2009 06:38:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/shortening-program/m-p/34027#M8263</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-05-28T06:38:55Z</dc:date>
    </item>
  </channel>
</rss>

