<?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 find codelist in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495689#M130874</link>
    <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find a MACRO that i can use to find the distinct number of patients having certain NDC numbers for different drugs. the thing is I want them to be stratified by drug names.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my code for which i want to create a MACRO for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	
%macro name(drug,ndc);
		
		proc sql;
			create table _02_&amp;amp;drug. as
			select count(distinct enrolid)  as patients 
			from data._01_md_cd_all 
			where NDCNUM in '&amp;amp;ndc.';
			;
		quit ;
	
	%mend name ;
	%name(evzio,'60842003001' ,'60842005101');
	%name(narcan,'1223456','32432453556');
	%name(bunavail,'343253254','324325446','4657687');
	%name(zubsolv,'435476','64756346','6768455,'3254367','5765425234');
	%name(buprenorphine,'34543645',4'324354');
	%name(suboxone,'43245354645','345354365'4365465,'6456436,'6434'64,'645634',6643653');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want the ndc&amp;nbsp;as another macro. how to do that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Sep 2018 14:00:42 GMT</pubDate>
    <dc:creator>manya92</dc:creator>
    <dc:date>2018-09-14T14:00:42Z</dc:date>
    <item>
      <title>find codelist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495689#M130874</link>
      <description>&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find a MACRO that i can use to find the distinct number of patients having certain NDC numbers for different drugs. the thing is I want them to be stratified by drug names.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's my code for which i want to create a MACRO for.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	
%macro name(drug,ndc);
		
		proc sql;
			create table _02_&amp;amp;drug. as
			select count(distinct enrolid)  as patients 
			from data._01_md_cd_all 
			where NDCNUM in '&amp;amp;ndc.';
			;
		quit ;
	
	%mend name ;
	%name(evzio,'60842003001' ,'60842005101');
	%name(narcan,'1223456','32432453556');
	%name(bunavail,'343253254','324325446','4657687');
	%name(zubsolv,'435476','64756346','6768455,'3254367','5765425234');
	%name(buprenorphine,'34543645',4'324354');
	%name(suboxone,'43245354645','345354365'4365465,'6456436,'6434'64,'645634',6643653');&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I want the ndc&amp;nbsp;as another macro. how to do that&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Sep 2018 14:00:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495689#M130874</guid>
      <dc:creator>manya92</dc:creator>
      <dc:date>2018-09-14T14:00:42Z</dc:date>
    </item>
    <item>
      <title>Re: find codelist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495692#M130877</link>
      <description>&lt;P&gt;Three steps ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;First, turn on the option that shows you what the generated SAS code looks like so you can identify errors:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;options MPRINT;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second, add parentheses and remove quotes inside the macro definition:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where NDCNUM in (&amp;amp;ndc.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Third, get rid of the commas in your macro call:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%name&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;narcan&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'1223456' &lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'32432453556'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The IN operator does not require commas between lists of character strings, and they cause havoc in the macro processor.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Sep 2018 14:07:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495692#M130877</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-09-14T14:07:38Z</dc:date>
    </item>
    <item>
      <title>Re: find codelist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495699#M130882</link>
      <description>&lt;P&gt;This is not a good way to approach the problem, you will maintenance of that data in that way very hard and prone to mistakes.&amp;nbsp; Create a dataset which contains name and the codes associated with that drug, something like:&lt;BR /&gt;DRUG&amp;nbsp; &amp;nbsp;CODE&lt;/P&gt;
&lt;P&gt;evzio&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;60842003001&lt;BR /&gt;evzio&amp;nbsp; &amp;nbsp; &amp;nbsp; 60842005101&lt;/P&gt;
&lt;P&gt;narcan&amp;nbsp; &amp;nbsp;1223456&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use that dataset to merge onto your raw data base on ndcnum=code to get drug.&amp;nbsp; This way your data can expand, shrink and change as with any other data, and its clear and easy, no macro code need, just one bit of simple merging:&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;proc sql;&lt;BR /&gt; create table _02 as&lt;BR /&gt; select b.drug,&lt;BR /&gt;        count(distinct a.enrolid) as patients &lt;BR /&gt; from   data._01_md_cd_all a&lt;BR /&gt; left join drugs b&lt;BR /&gt; on     a.ndcnum=b.code&lt;BR /&gt; group by drug;&lt;BR /&gt;quit;&lt;/PRE&gt;
&lt;P&gt;Or something like that.&amp;nbsp; note it is generally better to do by group processing rather than create lots of similar datasets and then try to join them together, its also faster, and simpler coding.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Sep 2018 14:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495699#M130882</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2018-09-14T14:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: find codelist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495705#M130884</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/208127"&gt;@manya92&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi all,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to find a MACRO that i can use to find the distinct number of patients having certain NDC numbers for different drugs. the thing is I want them to be stratified by drug names.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here's my code for which i want to create a MACRO for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	
%macro name(drug,ndc);
		
		proc sql;
			create table _02_&amp;amp;drug. as
			select count(distinct enrolid)  as patients 
			from data._01_md_cd_all 
			where NDCNUM in '&amp;amp;ndc.';
			;
		quit ;
	
	%mend name ;
	%name(evzio,'60842003001' ,'60842005101');
	%name(narcan,'1223456','32432453556');
	%name(bunavail,'343253254','324325446','4657687');
	%name(zubsolv,'435476','64756346','6768455,'3254367','5765425234');
	%name(buprenorphine,'34543645',4'324354');
	%name(suboxone,'43245354645','345354365'4365465,'6456436,'6434'64,'645634',6643653');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want the ndc&amp;nbsp;as another macro. how to do that&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Also, did you notice that your editor highlighting shows that your macro call&lt;/P&gt;
&lt;P&gt;%name(zubsolv,'435476','64756346','6768455,'3254367','5765425234');&lt;/P&gt;
&lt;P&gt;has errors if the commas were correct as '6768455 doesn't have a quote at the end.&lt;/P&gt;
&lt;P&gt;Plus others such as 4'&lt;SPAN class="token number"&gt;324354&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'&lt;/SPAN&gt;&amp;nbsp; &lt;SPAN class="token string"&gt;'6434'&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;64&lt;/SPAN&gt; have quotes in the middle of the value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think I would take a slightly different approach and create a custom format for the DSN values similar to&lt;/P&gt;
&lt;P&gt;(completely untested as I have no data)&lt;/P&gt;
&lt;PRE&gt;proc format library=work 
value $dsn2drug

'60842003001' ,'60842005101' =  'evzio'
'1223456','32432453556'	  ='narcan'
'343253254','324325446','4657687' =	  'bunavail'  
'435476','64756346','6768455','3254367','5765425234'	=  'zubsolv'  
'34543645','4324354'	 = 'buprenorphine'  
'43245354645','345354365','4365465','6456436','643464','645634','6643653'	= 'suboxone'&lt;BR /&gt;other='UNKNOWN'  
;
run;
%macro name(drug);
		
		proc sql;
			create table _02_&amp;amp;drug. as
			select count(distinct enrolid)  as patients 
			from data._01_md_cd_all 
			where upcase(put(NDCNUM,$dsn2drug.)) = upcase("&amp;amp;drug.");
			;
		quit ;
%mend;
%name (evzio) ;&lt;/PRE&gt;
&lt;P&gt;This approach would have the advantage of only adding an element to the format definition when a new code is needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That way you do not need to find in any of your code where the explicit value was listed and add that to the code.&lt;/P&gt;
&lt;P&gt;You need not even place the new code on an existing line. If I were to get a new dsn for evzio I could just ad&lt;/P&gt;
&lt;P&gt;'43241234'='evzio' at the end of the list in the format definition. Or if someone adds NDC's that have the dashes in the code values that I have seen in some data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The UPCASE in the sql is ensure matches encase you accidentally use different capitalization in the macro call(s) at different times:&lt;/P&gt;
&lt;P&gt;%name(Evzio)&lt;/P&gt;
&lt;P&gt;%name (evziO) would both have the same result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that with this approach you can also check your data set to see if any new codes have appeared with something like&lt;/P&gt;
&lt;PRE&gt;Proc sql;
   title "New NDC's";
   select NDCNUM 
   from data._01_md_cd_all
   where put(NDCNUM,$dsn2drug.) = "UNKNOWN";
quit;&lt;/PRE&gt;
&lt;P&gt;Of course if your NDC values are actual NUMERIC then no quotes should be used at all with the codes and the format name should not have the $.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Sep 2018 14:39:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495705#M130884</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-09-14T14:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: find codelist</title>
      <link>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495706#M130885</link>
      <description>&lt;P&gt;Is there a particular reason for a macro?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This could be done without a macro and in one step which may be significantly more efficient.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create a format for drug coding&lt;/P&gt;
&lt;P&gt;2. Apply format within SQL and use GROUP BY to get counts into single table.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value $ drug_class_fmt
'60842003001','60842005101' = 'evzio'
'1223456','32432453556' = 'narcan'
'343253254','324325446','4657687'= 'bunavail'
etc...

;
run;

proc sql;
	create table _02_summary_counts as
	select put(ndcnum, $drug_class_fmt.)  as drug,
                   count(distinct enrolid)  as patients 
	from data._01_md_cd_all 
	group by calculated drug
			;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 14 Sep 2018 14:40:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/find-codelist/m-p/495706#M130885</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-09-14T14:40:15Z</dc:date>
    </item>
  </channel>
</rss>

