<?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: How to search for a combination of 2 variables from a spreadsheet by using a macro? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/830014#M41287</link>
    <description>&lt;P&gt;Hi Tom&lt;/P&gt;&lt;P&gt;Thank you for taking the time to share this solution.&amp;nbsp; Indeed changing from a wide format to a long format could work.&lt;/P&gt;&lt;P&gt;Can you please let me know how to tweak the code so it searches for Diag that contains a wildcard, because the user might not need to enter the exact Diag to pick up everything that starts with I10 in your example? So&amp;nbsp;a.diag = b.diag might not always be an exact match.&lt;/P&gt;&lt;P&gt;Below I would like the pick up all ID that that contains I10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Aug 2022 23:32:00 GMT</pubDate>
    <dc:creator>mnsin24</dc:creator>
    <dc:date>2022-08-23T23:32:00Z</dc:date>
    <item>
      <title>How to search for a combination of 2 variables from a spreadsheet by using a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/829782#M41282</link>
      <description>&lt;P&gt;Hello there&lt;/P&gt;&lt;P&gt;My aim is&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;to use a spreadsheet where the end user can enter the codes( a combo of two codes) he wants to search (Input rule spreadsheet attached)&lt;/LI&gt;&lt;LI&gt;Load these codes into a macro&lt;/LI&gt;&lt;LI&gt;Use the macro in the coding to create alerts.&lt;/LI&gt;&lt;/UL&gt;&lt;PRE&gt;&lt;CODE class=""&gt;/* Importing inout file*/
PROC IMPORT
OUT=RuleCodes
datafile= "\\ar-prdsas02\SAS_User\testing loading file\Input rule.xlsx"
DBMS=xlsx REPLACE;
/*Sheet="Includes Excludes";*/
GETNAMES=YES;
DATAROW=2;
RUN;

/* Testing in multiple fields and this works*/
%macro Codes;
	%global Diag_codes1;
	proc sql noprint; 
	select Test_Diag into: Diag_codes1 separated by '" "'
	from RuleCodes;
	quit;
%mend;
%Codes;

/* creating another macro for secondary_diag*/
%macro Second_Diag;
	%global Diag_codes2;
	proc sql noprint; 
	select Test_Diag2 into: Diag_codes2 separated by '" "'
	from RuleCodes;
	quit;
%mend;
%Second_Diag;


Data Report_8ae;
set base_data4;
where Princ_Diag in: ("&amp;amp;Diag_codes1") AND 
(
(sdiag01 in: ("&amp;amp;Diag_codes2") or sdiag02 in: ("&amp;amp;Diag_codes2")
or sdiag03 in: ("&amp;amp;Diag_codes2") or sdiag04 in: ("&amp;amp;Diag_codes2")
or sdiag05 in: ("&amp;amp;Diag_codes2") or sdiag06 in: ("&amp;amp;Diag_codes2")
or sdiag07 in: ("&amp;amp;Diag_codes2") or sdiag08 in: ("&amp;amp;Diag_codes2")
or sdiag09 in: ("&amp;amp;Diag_codes2") or sdiag10 in: ("&amp;amp;Diag_codes2")
or sdiag11 in: ("&amp;amp;Diag_codes2") or sdiag12 in: ("&amp;amp;Diag_codes2")
or sdiag13 in: ("&amp;amp;Diag_codes2") or sdiag14 in: ("&amp;amp;Diag_codes2")
or sdiag15 in: ("&amp;amp;Diag_codes2") or sdiag16 in: ("&amp;amp;Diag_codes2")
or sdiag17 in: ("&amp;amp;Diag_codes2") or sdiag18 in: ("&amp;amp;Diag_codes2")
));
Report = '8e. Includes Excludes';
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have created macro Diag_codes1 to read the first code and Diag_codes2 to read the second code.&lt;/P&gt;&lt;P&gt;However the results I am getting is a combination of everything that is in Diag_codes1 and Diag_codes2 together.&lt;/P&gt;&lt;P&gt;What I need is line by line search of combination as per screenshot below&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="combination.PNG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74586i9CD4C6D17DBF6BFE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="combination.PNG" alt="combination.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am searching into basedata4 (attached) where Princ_diag and Sdiag (01 to 18) would match anything that has 2G45% AND 2I60% together. Then search again for the next combination.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I also have a concatenated field called All_diag (Princ_Diag and Sdiag01 - Sdiaf18 together) to make the search easier but the script below doesn't work with that either.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;PROC IMPORT
OUT=RuleCodes
datafile= "\\ar-prdsas02\SAS_User\testing loading file\Input rule.xlsx"
DBMS=xlsx REPLACE;
/*Sheet="Includes Excludes";*/
GETNAMES=YES;
DATAROW=2;
RUN;

/* create a macro for Combined*/
%macro Reference;
	%global Ref;
	proc sql noprint; 
	select Combine into: Ref separated by '" "'
	from RuleCodes;
	quit;
%mend;
%Reference;&lt;BR /&gt;
Data Report_8ae;
set base_data4;
where All_Diag in: ("&amp;amp;Ref");
Report = '8e. Includes Excludes';
run; &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I have these Diag hard coded and currently working in a script, however the user needs to add those Diag codes on a daily basis and we thought more efficient to feed these codes from a spreadsheet that then feeds into the script.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any assistance on how I could move forward with that would be highly appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 01:27:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/829782#M41282</guid>
      <dc:creator>mnsin24</dc:creator>
      <dc:date>2022-08-23T01:27:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a combination of 2 variables from a spreadsheet by using a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/829790#M41283</link>
      <description>&lt;P&gt;If you restructure your data so each subject's diagnosis code is on a SEPARATE observation then you are just need to use an simple JOIN to figure out if any subject has any diagnosis codes that are in the groupings in your list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data subjects;
  input id :$10. diag :$8. ;
cards;
340546 I10BF
340546 2G553
340546 2M5387
348117 Q61BS
;

data rules;
  input rule diag :$8. ;
cards;
1 I10BF
2 2G553
;

proc sql;
create table want as 
  select a.id
       , b.rule
       , max( a.diag = b.diag) as value
  from subjects a
     , rules b
  group by 1,2
;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;PRE&gt;Obs      id      rule    value

 1     340546      1       1
 2     340546      2       1
 3     348117      1       0
 4     348117      2       0
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 04:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/829790#M41283</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-23T04:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a combination of 2 variables from a spreadsheet by using a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/830014#M41287</link>
      <description>&lt;P&gt;Hi Tom&lt;/P&gt;&lt;P&gt;Thank you for taking the time to share this solution.&amp;nbsp; Indeed changing from a wide format to a long format could work.&lt;/P&gt;&lt;P&gt;Can you please let me know how to tweak the code so it searches for Diag that contains a wildcard, because the user might not need to enter the exact Diag to pick up everything that starts with I10 in your example? So&amp;nbsp;a.diag = b.diag might not always be an exact match.&lt;/P&gt;&lt;P&gt;Below I would like the pick up all ID that that contains I10.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Aug 2022 23:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/830014#M41287</guid>
      <dc:creator>mnsin24</dc:creator>
      <dc:date>2022-08-23T23:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a combination of 2 variables from a spreadsheet by using a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/830017#M41288</link>
      <description>I have tweaked the script to read&lt;BR /&gt;where a.diag like catt('%',b.diag,'%')&lt;BR /&gt;and it seems to be working.&lt;BR /&gt;&lt;BR /&gt;Let me test against the real dataset and will confirm if it works.&lt;BR /&gt;Thanks again!</description>
      <pubDate>Wed, 24 Aug 2022 00:29:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/830017#M41288</guid>
      <dc:creator>mnsin24</dc:creator>
      <dc:date>2022-08-24T00:29:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a combination of 2 variables from a spreadsheet by using a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/830019#M41289</link>
      <description>&lt;P&gt;That can work, but you do not want the leading %.&amp;nbsp; That would not make any sense with ICD-10 diagnosis codes.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Aug 2022 02:11:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/830019#M41289</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-24T02:11:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to search for a combination of 2 variables from a spreadsheet by using a macro?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/830020#M41290</link>
      <description>Yes True! I will remove the leading % and only keep the second one.&lt;BR /&gt;Thanks a lot for your help Tom!</description>
      <pubDate>Wed, 24 Aug 2022 02:17:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/How-to-search-for-a-combination-of-2-variables-from-a/m-p/830020#M41290</guid>
      <dc:creator>mnsin24</dc:creator>
      <dc:date>2022-08-24T02:17:17Z</dc:date>
    </item>
  </channel>
</rss>

