<?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: Capturing data in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585660#M167070</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;You'd need the corresponding number of FIND expressions conjugated by ORs. But in such a case, it's simpler, easier, and less verbose to use the PRXMATCH function - you can judge by comparing the line where it's used with the commented out line with the FINDs below (both lines yield the same result):&lt;/P&gt;
&lt;PRE&gt;data have ;                                                                                 
  input (diag1-diag3) (:$6.) ;                                                              
  cards ;                                                                                   
251  J441   450XY                                                                           
1&lt;FONT color="#800000"&gt;&lt;STRONG&gt;J21&lt;/STRONG&gt;&lt;/FONT&gt;  J451  J458                                                                            
J469 J46    J46X                                                                            
R062 &lt;FONT color="#800000"&gt;&lt;STRONG&gt;J0&lt;/STRONG&gt;&lt;/FONT&gt;XX   J441                                                                            
J455 45XX   J46X                                                                            
262  263    62&lt;FONT color="#800000"&gt;&lt;STRONG&gt;J38&lt;/STRONG&gt;&lt;/FONT&gt;                                                                           
K52  P783   A00                                                                             
A02  A0&lt;FONT color="#800000"&gt;&lt;STRONG&gt;J37&lt;/STRONG&gt;&lt;/FONT&gt;3 A04                                                                             
run ;                                                                                       
                                                                                            
data want (drop = _:) ;                                                                     
  set have ;                                                                                
  array dd diag: ;                                                                          
  do over dd ;                                                                              
    if prxmatch ("m/J21|J0|J38|J37/oi", dd) then do ;                                       
  * if find (dd, "J21") or find (dd, "J0") or find (dd, "J38") or find (dd, "J37") then do ;
      _exclude = 1 ;                                                                        
      leave ;                                                                               
    end ;                                                                                   
  end ;                                                                                     
  if not _exclude ;                                                                         
run ;                                                                                       
&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 02 Sep 2019 20:30:50 GMT</pubDate>
    <dc:creator>hashman</dc:creator>
    <dc:date>2019-09-02T20:30:50Z</dc:date>
    <item>
      <title>Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582146#M165521</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I got some variables on say for example diagnosis which can be coded as 45, 451, 459, 458. So all these observations have 45 in common. I want to capture all observations which has values starting with 45 without writing an entire list of codes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I do that please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 15:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582146#M165521</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-08-19T15:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582150#M165524</link>
      <description>Is it numeric or character variables?&lt;BR /&gt;&lt;BR /&gt;If character use a colon operator with the equal sign to check the first two characters only. &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;if diag_code =: '45';&lt;BR /&gt;</description>
      <pubDate>Mon, 19 Aug 2019 16:02:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582150#M165524</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-08-19T16:02:15Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582162#M165527</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
x=45;  output;
x=451; output;
x=459; output;
x=458; output;
x=75;  output;
x=951; output;
x=729; output;
x=458; output;
run;

data want;
	set have;
	if substr(left(x),1,2)='45';
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Aug 2019 16:27:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582162#M165527</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-08-19T16:27:05Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582191#M165548</link>
      <description>&lt;P&gt;If you have multiple variables you&amp;nbsp; may want to consider an array and testing each value, such as with &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s approach and if none of the variables match, then delete the record. Ease may depend on number of variables involved:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One way with some very limited character data:&lt;/P&gt;
&lt;PRE&gt;data example;
   informat d1-d3 $5.;
   input d1 d2 d3;
   array d d1-d3;
   flag=0;
   do i= 1 to dim(d);
      flag= (d[i] =: '45');
      if flag then leave;
   end;
   if flag=0 then delete;
   drop i flag;

datalines;
123 456 789
123 234 642
450 124 444
123 124 459
;
run;&lt;/PRE&gt;
&lt;P&gt;A question that my need consideration:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Do you have values such as '45123', longer than the 3 characters that you showed that show NOT be considered as in the wanted&amp;nbsp; values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Aug 2019 17:42:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582191#M165548</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-08-19T17:42:49Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582306#M165603</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;Frankly, I have an aversion to implicit data type conversions, so I'd rather do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                    
  do x = 45, 451, 459, 458, 75, 951, 729, 458 ;
    output ;                                   
  end ;                                        
run ;                                          
                                               
data want ;                                    
  set have ;                                   
  if put (x, D.-L) =: "45" ;                   
run ;                                          
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or, without any type conversions, explicit or implicit:&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;data want ;                                       
  set have ;                                      
  if int (x / 10 ** (int (log10 (x)) - 1)) = 45 ;
run ;                                             
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;That having been said, codes of this nature are always of the character type (usually $5), as they may contain alphas. Hence, it would be apter to model the sample data set accordingly, which in turn makes the subsetting process much simpler:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                      
  do _n_ = 45, 451, 459, 458, 75, 951, 729, 458 ;
    x = put (_n_, 5.-L) ;                        
    output ;                                     
  end ;                                          
run ;                                            
                                                 
data want ;                                      
  set have (where = (x =: "45")) ;                                 
run ;                                            
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 04:11:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582306#M165603</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-20T04:11:49Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582350#M165625</link>
      <description>&lt;P&gt;Yes, I am looking for&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'251', 'J441','J450', 'J45', 'J451','J458', 'J459', 'J46', 'J46X', 'R062', 'J44.1', 'J441-', 'J44x'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;in a number of variables named as 'diag_01 to diag_06'.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I write that in syntax please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 09:02:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582350#M165625</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-08-20T09:02:03Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582355#M165629</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Essentially the same way&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;has already suggested:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop = _:) ;
  set have ;
  array d diag: ;
  do over d ;
    if d in ('251', 'J441','J450', 'J45', 'J451','J458', 'J459', 'J46', 'J46X', 'R062', 'J44.1', 'J441-', 'J44x') then do ;
      _FOUND = 1 ;
      leave ;&lt;BR /&gt;    end ;
  end ;
  if _FOUND ; * if you want only the records where you have a match ;
run ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Aug 2019 09:20:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/582355#M165629</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-20T09:20:45Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/583475#M166100</link>
      <description>&lt;P&gt;But this code does involve listing all the values and in this specific case I don't know the exact values, as some clinicians would have coded a diagnosis as '45', another as '45X' and another as '45.0', so I don't want to worry about what comes after '45'. I only want to tell SAS to pick any value starting with 45 regardless of 'X', '.', '-' etc. etc.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do I write that please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 13:55:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/583475#M166100</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-08-23T13:55:39Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/583498#M166108</link>
      <description>&lt;P&gt;Also wanted to ask if SAS would take '05 17R' as '0517R' or do I have to specify space between 05 and 17R.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 14:54:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/583498#M166108</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-08-23T14:54:09Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/583586#M166134</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Sorry, but I'm confused now.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You said that you wanted to pick the values that start with 45.&lt;/P&gt;
&lt;P&gt;Yet you also gave a sample of codes, &lt;EM&gt;none of which starts with 45&lt;/EM&gt; but may &lt;EM&gt;start with a letter (for instance, J) followed by 45&lt;/EM&gt;:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;'251', 'J441','J450', 'J45', 'J451','J458', 'J459', 'J46', 'J46X', 'R062', 'J44.1', 'J441-', 'J44x'&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Which makes me conjecture that you want make your SAS code react to the codes whose &lt;EM&gt;first two &lt;FONT color="#0000FF"&gt;digits&lt;/FONT&gt; are 45&lt;/EM&gt;, regardless of whether they are preceded by a non-digit or not. In other words, if my conjecture held water, you'd like SAS to react to the following selection from the above list:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;'J450', 'J45', 'J451','J458', 'J459'&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Is that correct? If so, your condition should begin with the &lt;EM&gt;first digit&lt;/EM&gt; in any code, rather than at character #1. In other words, given the data sample HAVE below, you'd want to select records #1, 2, and 5:&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                        
  input (diag1-diag3) (:$5.) ;                     
  cards ;                                          
251  J441  450XY                                   
J45  J451  J458                                    
J469 J46   J46X                                    
R062 J44.1 J441                                    
J469 45XX  J46X                                    
run ;                                              
                                                   
data want (drop = _select) ;                      
  set have ;                                       
  array dd diag: ;                                 
  do over dd ;                                     
    if substr (dd, anydigit (dd)) =: "45" then do ;
      _select = 1 ;                                
      leave ;                                      
    end ;                                          
  end ;                                            
  if _select ;                                     
run ;                                              
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Instead of the expression:&lt;/P&gt;
&lt;PRE&gt;substr (dd, anydigit (dd))&lt;/PRE&gt;
&lt;P&gt;you can also use:&lt;/P&gt;
&lt;PRE&gt;compress (dd, , "kd")
&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&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;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 23 Aug 2019 19:02:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/583586#M166134</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-08-23T19:02:25Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585559#M167002</link>
      <description>&lt;P&gt;Hi Paul,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry about the confusion. I was just giving an example as got multiple diagnoses that I would want to pick up using this code. Here is the description;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Gastroenteritis is entered as&amp;nbsp;&lt;/P&gt;&lt;P&gt;262, 263, 262248, K52, P783, A00, A02, A03, A04, A05, A06, A07, A08, A09, A084, A080, A083, A059, A090, A099&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and asthma is coded as;&lt;/P&gt;&lt;P&gt;251, 251228, J441, J450, J45, J451, J458, J459, J46, J46X, R062&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I would, say for example, want to pick any codes that have 26, A0 for gastroenteritis and J44, J45, 251 for asthma.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How would I write it please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 09:30:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585559#M167002</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-09-02T09:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585567#M167010</link>
      <description>&lt;P&gt;And also, how do we write this array if we wanted to drop observations with diagnoses codes (given in variables diag_01 to diag_09) including values like J21, J0, J38, J37 regardless of values/digits/characters before and after them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 10:04:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585567#M167010</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-09-02T10:04:38Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585658#M167069</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;Just apply a separate condition with the colon modifier for each spec condition:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;                                             
  input (diag1-diag3) (:$6.) ;                          
  cards ;                                               
251  J441   450XY                                       
J45  J451   J458                                        
J469 J46    J46X                                        
R062 J44.1  J441                                        
J469 45XX   J46X                                        
262  263    262248                                      
K52  P783   A00                                         
A02  A03    A04                                         
A05  A06    A07                                         
A08  A09    A084                                        
A080 A083   A059                                        
251  251228 J441                                        
J450 J45    J451                                        
J458 J459   J46                                         
J46X R062   P783                                        
run ;                                                   
                                                        
data want ;                                             
  set have ;                                            
  array dd diag: ;                                      
  do over dd ;                                          
    if dd in: ("26"  "A0"       ) then flag_gastro = 1 ;
    if dd in: ("J44" "J45" "251") then flag_asthma = 1 ;
  end ;                                                 
* if flag_gastro or flag_asthma ;                       
* drop flag_: ;                                         
run ;                                                   
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want only the output observations with either gastro or asthma codes found, uncomment the two penultimate lines.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 20:10:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585658#M167069</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-02T20:10:14Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585660#M167070</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;You'd need the corresponding number of FIND expressions conjugated by ORs. But in such a case, it's simpler, easier, and less verbose to use the PRXMATCH function - you can judge by comparing the line where it's used with the commented out line with the FINDs below (both lines yield the same result):&lt;/P&gt;
&lt;PRE&gt;data have ;                                                                                 
  input (diag1-diag3) (:$6.) ;                                                              
  cards ;                                                                                   
251  J441   450XY                                                                           
1&lt;FONT color="#800000"&gt;&lt;STRONG&gt;J21&lt;/STRONG&gt;&lt;/FONT&gt;  J451  J458                                                                            
J469 J46    J46X                                                                            
R062 &lt;FONT color="#800000"&gt;&lt;STRONG&gt;J0&lt;/STRONG&gt;&lt;/FONT&gt;XX   J441                                                                            
J455 45XX   J46X                                                                            
262  263    62&lt;FONT color="#800000"&gt;&lt;STRONG&gt;J38&lt;/STRONG&gt;&lt;/FONT&gt;                                                                           
K52  P783   A00                                                                             
A02  A0&lt;FONT color="#800000"&gt;&lt;STRONG&gt;J37&lt;/STRONG&gt;&lt;/FONT&gt;3 A04                                                                             
run ;                                                                                       
                                                                                            
data want (drop = _:) ;                                                                     
  set have ;                                                                                
  array dd diag: ;                                                                          
  do over dd ;                                                                              
    if prxmatch ("m/J21|J0|J38|J37/oi", dd) then do ;                                       
  * if find (dd, "J21") or find (dd, "J0") or find (dd, "J38") or find (dd, "J37") then do ;
      _exclude = 1 ;                                                                        
      leave ;                                                                               
    end ;                                                                                   
  end ;                                                                                     
  if not _exclude ;                                                                         
run ;                                                                                       
&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 20:30:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585660#M167070</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-02T20:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585669#M167074</link>
      <description>&lt;P&gt;Or :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data HAVE ;                                                                                 
  input (DIAG1-DIAG3) (:$6.) ;                                                              
  cards ;                                                                                   
251  J441   450XY                                                                           
1J21  J451  J458                                                                            
J469 J46    J46X                                                                            
R062 J0XX   J441                                                                            
J455 45XX   J46X                                                                            
262  263    62J38                                                                           
K52  P783   A00                                                                             
A02  A0J373 A04                                                                             
run;                                                                                       
                                                                                            
data WANT;                                                                     
  set HAVE;                                                                                
  FLAG_GASTRO=prxmatch ("m/\b26|\bA0/oi"        , catx(' ',of DIAG:)) &amp;gt; 0;                                       
  FLAG_ASTHMA=prxmatch ("m/\bJ44|\bJ45|\b251/oi", catx(' ',of DIAG:)) &amp;gt; 0;                                       
run;           &lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;&lt;BR /&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="l header" scope="col"&gt;DIAG1&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;DIAG2&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;DIAG3&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;FLAG_GASTRO&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;FLAG_ASTHMA&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;251&lt;/TD&gt;
&lt;TD class="l data"&gt;J441&lt;/TD&gt;
&lt;TD class="l data"&gt;450XY&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;1J21&lt;/TD&gt;
&lt;TD class="l data"&gt;J451&lt;/TD&gt;
&lt;TD class="l data"&gt;J458&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;J469&lt;/TD&gt;
&lt;TD class="l data"&gt;J46&lt;/TD&gt;
&lt;TD class="l data"&gt;J46X&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;R062&lt;/TD&gt;
&lt;TD class="l data"&gt;J0XX&lt;/TD&gt;
&lt;TD class="l data"&gt;J441&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;J455&lt;/TD&gt;
&lt;TD class="l data"&gt;45XX&lt;/TD&gt;
&lt;TD class="l data"&gt;J46X&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;262&lt;/TD&gt;
&lt;TD class="l data"&gt;263&lt;/TD&gt;
&lt;TD class="l data"&gt;62J38&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;K52&lt;/TD&gt;
&lt;TD class="l data"&gt;P783&lt;/TD&gt;
&lt;TD class="l data"&gt;A00&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="l data"&gt;A02&lt;/TD&gt;
&lt;TD class="l data"&gt;A0J373&lt;/TD&gt;
&lt;TD class="l data"&gt;A04&lt;/TD&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="r data"&gt;0&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;P&gt;\b&amp;nbsp; means the word begins there&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 01:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585669#M167074</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-09-03T01:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585671#M167075</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Very clever!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Committed to my storage.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Mon, 02 Sep 2019 22:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585671#M167075</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-02T22:19:32Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585723#M167106</link>
      <description>&lt;P&gt;I have run this array but getting an error message as follows; (these are all character variables listed as treat_01 to treat_12)&lt;/P&gt;&lt;PRE&gt;285  data CONTROL1 (drop = _:) ;
286    set VISITS ;
287    array dd TREAT: ;
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
ERROR: All variables in array list must be the same type, i.e., all numeric or character.
288    do over dd ;
289      if prxmatch ("m/J21|J0|J38|J37/oi", dd) then do ;
290    * if find (dd, "J21") or find (dd, "J0") or find (dd, "J38") or find (dd, "J37") then do ;
291        _exclude = 1 ;
292        leave ;
293      end ;
294    end ;
295    if not _exclude ;
296  run ;

NOTE: Numeric values have been converted to character values at the places given by:
      (Line):(Column).
      289:41
NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.CONTROL1 may be incomplete.  When this step was stopped there were 0
         observations and 30 variables.
WARNING: Data set WORK.CONTROL1 was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.01 seconds&lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Sep 2019 08:56:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585723#M167106</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-09-03T08:56:12Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585746#M167117</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/277970"&gt;@sks521&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;The SAS log tells you plainly that different TREAT* variables have both character and numeric data types. From the standpoint of process organization and the nature of the task, this is called "dirty data": They should be all character.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The &lt;EM&gt;proper&lt;/EM&gt; solution is to convert all the numeric TREAT variables to character; then the code will run error-free.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;A palliative solution is to use the CATX trick offered by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/16961"&gt;@ChrisNZ&lt;/a&gt;, as unlike an array, the collective colon (:) modifier reference doesn't suggest the same data type across all TREAT: variables&amp;nbsp;in the context of using it with the CATX function, since the latter converts numeric variables to the character type automatically:&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT ;                                                                     
  set HAVE ;                                                                                
  if prxmatch ("m/\b26|\bA0/oi", catx (' ', of TREAT:)) = 0
  and                                       
  prxmatch ("m/\bJ44|\bJ45|\b251/oi", catx (' ', of TREAT:)) = 0
  ;                                       
run ;           &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 10:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585746#M167117</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-09-03T10:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585750#M167121</link>
      <description>&lt;P&gt;Thanks but can I check in if this step will get rid of all observations with any diagnoses other than the ones specified (asthma and gastroenteritis) here please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;S&lt;/P&gt;</description>
      <pubDate>Tue, 03 Sep 2019 10:54:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585750#M167121</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-09-03T10:54:13Z</dc:date>
    </item>
    <item>
      <title>Re: Capturing data</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585833#M167160</link>
      <description>&lt;P&gt;Hi Paul,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;These are all character variables and I have defined them as character variables while importing data into SAS. How come&amp;nbsp; I am getting errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And also I have tried to use the syntax you suggested but still getting errors, this time using diagnosis variables;&lt;/P&gt;&lt;PRE&gt;*Deleting observations with croup diagnosis;
*USING ARRAY FROM THE SAS SUPPORT COMMUNITY;
data CONTROL1 (drop = _:) ;                                                                     
  set VISITS ;                                                                                
  array dd diag: ;                                                                          
  do over dd ;                                                                              
    if prxmatch ("m/J05/oi", catx (' ', of diag:)) then do ;                                       
  * if find (dd, "J21") or find (dd, "J0") or find (dd, "J38") or find (dd, "J37") then do ;
      _exclude = 1 ;                                                                        
      leave ;                                                                               
    end ;                                                                                   
  end ;                                                                                     
  if not _exclude ;                                                                         
run ;       &lt;/PRE&gt;</description>
      <pubDate>Tue, 03 Sep 2019 14:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Capturing-data/m-p/585833#M167160</guid>
      <dc:creator>sks521</dc:creator>
      <dc:date>2019-09-03T14:20:16Z</dc:date>
    </item>
  </channel>
</rss>

