<?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: %LET macro statement from an Excel sheet in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement-from-an-Excel-sheet/m-p/577429#M163622</link>
    <description>&lt;P&gt;Figured it out!&lt;/P&gt;&lt;P&gt;Here it is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NDCs;
&amp;nbsp; &amp;nbsp; length
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ndc&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$ 11
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name&amp;nbsp; &amp;nbsp; $ 15;



&amp;nbsp; &amp;nbsp; set xl.'CPT'n&amp;nbsp; &amp;nbsp; &amp;nbsp;(keep=ndc name)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xl.'ICD_PR'n  (keep=ndc name)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xl.'ICD_DX'n  (keep=ndc name)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xl.'DRG'n&amp;nbsp; &amp;nbsp; &amp;nbsp;(keep=ndc name)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xl.'NDC'n&amp;nbsp; &amp;nbsp; &amp;nbsp;(keep=ndc name);
&amp;nbsp; &amp;nbsp; where
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NDC^= ' ';
run;



libname xl clear;



proc sql;
&amp;nbsp; &amp;nbsp; create table names as
&amp;nbsp; &amp;nbsp; select distinct
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name
&amp;nbsp; &amp;nbsp; from NDCs

;quit;



%macro codes(name);
&amp;nbsp; &amp;nbsp; %global &amp;amp;name;



&amp;nbsp; &amp;nbsp; proc sql;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select distinct
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; quote(strip(code)) into: &amp;amp;name separated by ','
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from codes
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name = "&amp;amp;name"
&amp;nbsp; &amp;nbsp; ;quit;
%mend;



data _null_;
&amp;nbsp; &amp;nbsp; set names;
&amp;nbsp; &amp;nbsp; call execute('%codes('||name||');');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 29 Jul 2019 16:31:23 GMT</pubDate>
    <dc:creator>Paige1</dc:creator>
    <dc:date>2019-07-29T16:31:23Z</dc:date>
    <item>
      <title>%LET macro statement from an Excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement-from-an-Excel-sheet/m-p/577391#M163611</link>
      <description>&lt;P&gt;I have an Excel file with NDCs and Categorys. Here is a sample from it:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;NDC&lt;/TD&gt;&lt;TD&gt;Category&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00536114941&lt;/TD&gt;&lt;TD&gt;NSAID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00536308610&lt;/TD&gt;&lt;TD&gt;NSAID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00536308641&lt;/TD&gt;&lt;TD&gt;NSAID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00536331301&lt;/TD&gt;&lt;TD&gt;NSAID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00536331310&lt;/TD&gt;&lt;TD&gt;NSAID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00603002622&lt;/TD&gt;&lt;TD&gt;NSAID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;57881033632&lt;/TD&gt;&lt;TD&gt;Opioid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;57881033832&lt;/TD&gt;&lt;TD&gt;Opioid&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00093005001&lt;/TD&gt;&lt;TD&gt;Opioid-other&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;00093015001&lt;/TD&gt;&lt;TD&gt;Opioid-other&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;69344011111&lt;/TD&gt;&lt;TD&gt;Opioid-NSAID&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;69344021111&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Opioid-NSAID&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;etc...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a %LET statement in SAS using the Excel sheet that would do the same thing as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%LET NSAID = 00536114941 00536308610 00536305641 00536331301 00536331310 00603002622;&lt;/P&gt;&lt;P&gt;%LET Opioid = 57881033632 578810832;&lt;/P&gt;&lt;P&gt;%LET Opioid_other = 00093005001 00093015001;&lt;/P&gt;&lt;P&gt;%LET Opoioid_NSAID = 69344011111 69344021111;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I want to make it so that if I make changes to the Excel sheet, it will automatically update in SAS--that is I want to use SAS code that creates a %LET statement FROM the Excel file, not copy paste from Excel into SAS.&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jul 2019 15:08:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement-from-an-Excel-sheet/m-p/577391#M163611</guid>
      <dc:creator>Paige1</dc:creator>
      <dc:date>2019-07-29T15:08:07Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement from an Excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement-from-an-Excel-sheet/m-p/577399#M163613</link>
      <description>I have a feeling if you explain your usage a data driven format will be much more appropriate. You can import the data and create the format from the imported data set so it's a fully dynamic solution.</description>
      <pubDate>Mon, 29 Jul 2019 15:14:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement-from-an-Excel-sheet/m-p/577399#M163613</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-29T15:14:20Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement from an Excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement-from-an-Excel-sheet/m-p/577400#M163614</link>
      <description>Storing data in macro-variables is almost always a bad idea and I can't remember any case that wasn't solvable without using macro variables. &lt;BR /&gt;&lt;BR /&gt;Step 1 import the excel file. &lt;BR /&gt;Step 2 change the value of Category, so that it contains only valid sas names. Check that you don't modify a value so that it is the same as the value ready in the dataset. &lt;BR /&gt;Step 3 use a data step with by and retain to build the value-list per category. On last category use call symputx to create a macro-variable. &lt;BR /&gt;&lt;BR /&gt;If you want code, please provide data in usable from: a data-step using datalines, NO excel-files, please.</description>
      <pubDate>Mon, 29 Jul 2019 15:20:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement-from-an-Excel-sheet/m-p/577400#M163614</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-07-29T15:20:13Z</dc:date>
    </item>
    <item>
      <title>Re: %LET macro statement from an Excel sheet</title>
      <link>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement-from-an-Excel-sheet/m-p/577429#M163622</link>
      <description>&lt;P&gt;Figured it out!&lt;/P&gt;&lt;P&gt;Here it is:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data NDCs;
&amp;nbsp; &amp;nbsp; length
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ndc&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;$ 11
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name&amp;nbsp; &amp;nbsp; $ 15;



&amp;nbsp; &amp;nbsp; set xl.'CPT'n&amp;nbsp; &amp;nbsp; &amp;nbsp;(keep=ndc name)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xl.'ICD_PR'n  (keep=ndc name)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xl.'ICD_DX'n  (keep=ndc name)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xl.'DRG'n&amp;nbsp; &amp;nbsp; &amp;nbsp;(keep=ndc name)
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; xl.'NDC'n&amp;nbsp; &amp;nbsp; &amp;nbsp;(keep=ndc name);
&amp;nbsp; &amp;nbsp; where
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; NDC^= ' ';
run;



libname xl clear;



proc sql;
&amp;nbsp; &amp;nbsp; create table names as
&amp;nbsp; &amp;nbsp; select distinct
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name
&amp;nbsp; &amp;nbsp; from NDCs

;quit;



%macro codes(name);
&amp;nbsp; &amp;nbsp; %global &amp;amp;name;



&amp;nbsp; &amp;nbsp; proc sql;
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; select distinct
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; quote(strip(code)) into: &amp;amp;name separated by ','
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; from codes
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; where
&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; name = "&amp;amp;name"
&amp;nbsp; &amp;nbsp; ;quit;
%mend;



data _null_;
&amp;nbsp; &amp;nbsp; set names;
&amp;nbsp; &amp;nbsp; call execute('%codes('||name||');');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 29 Jul 2019 16:31:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/LET-macro-statement-from-an-Excel-sheet/m-p/577429#M163622</guid>
      <dc:creator>Paige1</dc:creator>
      <dc:date>2019-07-29T16:31:23Z</dc:date>
    </item>
  </channel>
</rss>

