<?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 help calling macro from data step in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189598#M35776</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My data has a column called program_name and I want to generate a report for each program_name. I have a proc sql query that gets a distinct list of the program names. Some of the program names consist of more than one word. My code works for the program names that are only one word but fails for the program names of two or more words. How do I get it to work for program names of more than one word? Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data prg_names1;&lt;BR /&gt;input @1 program_name $22. @23 did 3.;&lt;BR /&gt;datalines;&lt;BR /&gt;math&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 301&lt;BR /&gt;english&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 302&lt;BR /&gt;social studies&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 303&lt;BR /&gt;environmental science 304&lt;BR /&gt;biology&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 305&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT MLOGIC;&lt;BR /&gt;%macro exportprograms(program);&lt;BR /&gt; proc sql;&lt;BR /&gt;&amp;nbsp; create table &amp;amp;program as&lt;BR /&gt;&amp;nbsp; select *&lt;BR /&gt;&amp;nbsp; from prg_names1&lt;BR /&gt;&amp;nbsp; where program_name = "&amp;amp;program";&lt;BR /&gt; run;&lt;BR /&gt; proc export data=&amp;amp;program&lt;BR /&gt;&amp;nbsp; outfile="&amp;amp;destn/&amp;amp;reportnm._&amp;amp;program..xlsx"&lt;BR /&gt;&amp;nbsp; dbms=xlsx replace;&lt;BR /&gt; run;&lt;BR /&gt;%mend exportprograms;&lt;BR /&gt;/*%exportprograms(math);*/&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt; set prg_names1;&lt;BR /&gt;/* length program $ 50;*/&lt;BR /&gt;/* call symputx('program',program_name);*/&lt;BR /&gt;/* call execute('%exportprograms(program_name)');*/&lt;BR /&gt; call execute('%exportprograms(program=' || program_name || ')' );&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 17 Oct 2014 15:27:51 GMT</pubDate>
    <dc:creator>dan999</dc:creator>
    <dc:date>2014-10-17T15:27:51Z</dc:date>
    <item>
      <title>help calling macro from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189598#M35776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My data has a column called program_name and I want to generate a report for each program_name. I have a proc sql query that gets a distinct list of the program names. Some of the program names consist of more than one word. My code works for the program names that are only one word but fails for the program names of two or more words. How do I get it to work for program names of more than one word? Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data prg_names1;&lt;BR /&gt;input @1 program_name $22. @23 did 3.;&lt;BR /&gt;datalines;&lt;BR /&gt;math&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 301&lt;BR /&gt;english&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 302&lt;BR /&gt;social studies&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 303&lt;BR /&gt;environmental science 304&lt;BR /&gt;biology&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 305&lt;BR /&gt;;&lt;BR /&gt;run;&lt;BR /&gt;OPTIONS SOURCE SOURCE2 MACROGEN SYMBOLGEN MPRINT MLOGIC;&lt;BR /&gt;%macro exportprograms(program);&lt;BR /&gt; proc sql;&lt;BR /&gt;&amp;nbsp; create table &amp;amp;program as&lt;BR /&gt;&amp;nbsp; select *&lt;BR /&gt;&amp;nbsp; from prg_names1&lt;BR /&gt;&amp;nbsp; where program_name = "&amp;amp;program";&lt;BR /&gt; run;&lt;BR /&gt; proc export data=&amp;amp;program&lt;BR /&gt;&amp;nbsp; outfile="&amp;amp;destn/&amp;amp;reportnm._&amp;amp;program..xlsx"&lt;BR /&gt;&amp;nbsp; dbms=xlsx replace;&lt;BR /&gt; run;&lt;BR /&gt;%mend exportprograms;&lt;BR /&gt;/*%exportprograms(math);*/&lt;/P&gt;&lt;P&gt;data _null_;&lt;BR /&gt; set prg_names1;&lt;BR /&gt;/* length program $ 50;*/&lt;BR /&gt;/* call symputx('program',program_name);*/&lt;BR /&gt;/* call execute('%exportprograms(program_name)');*/&lt;BR /&gt; call execute('%exportprograms(program=' || program_name || ')' );&lt;BR /&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 15:27:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189598#M35776</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2014-10-17T15:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: help calling macro from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189599#M35777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let's look at a word with a space in it, ie Social Studies&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your Code that SAS would Generate, which would have showed in your log with the mprint and symbolgen options.&lt;/P&gt;&lt;P&gt;That isn't valid SAS code, so I would consider how to deal with that.&lt;/P&gt;&lt;P&gt;Create a new macro variable that will meet the SAS naming conventions by eIther remove spaces or replace with underscore and pass that to the program instead.&lt;/P&gt;&lt;P&gt;You could also change the options to validvarname=any but I wouldn't recommend that. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table &lt;SPAN style="text-decoration: underline; color: #ff0000;"&gt;&lt;STRONG&gt;Social Studies&lt;/STRONG&gt;&lt;/SPAN&gt; as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select *&lt;/P&gt;&lt;P&gt;&amp;nbsp; from prg_names1&lt;/P&gt;&lt;P&gt;&amp;nbsp; where program_name = "Social Studies";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;proc export data=&lt;SPAN style="text-decoration: underline; color: #ff0000;"&gt;&lt;STRONG&gt;Social Studies&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; outfile="&amp;amp;destn/&amp;amp;reportnm._Social Studies..xlsx"&lt;/P&gt;&lt;P&gt;&amp;nbsp; dbms=xlsx replace;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 15:34:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189599#M35777</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-10-17T15:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: help calling macro from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189600#M35778</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm not sure what you mean by "isn't valid SAS code". Could you explain further. It works for programs with only one word. Your suggestion to remove spaces or add an underscore wouldn't work because the query in the macro wouldn't match a program with those new program names. Unless, I change the program names in the result set first. I've thought of that but I was hoping there was a way to do this without resorting to that.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 17:37:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189600#M35778</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2014-10-17T17:37:04Z</dc:date>
    </item>
    <item>
      <title>Re: help calling macro from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189601#M35779</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Data set names in SAS are not allowed to have spaces. Check the online help for "Rules for SAS Data Set Names, View Names, and Item Store Names". A simple fix is to replace the spaces in those names with the _ character.&lt;/P&gt;&lt;P&gt;You should have been getting error messages in log with your attempted syntax.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 17:51:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189601#M35779</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-10-17T17:51:41Z</dc:date>
    </item>
    <item>
      <title>Re: help calling macro from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189602#M35780</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The first is what your code is providing the equivalent of:. &lt;/P&gt;&lt;P&gt;Do you see the error now?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table female only as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select *&lt;/P&gt;&lt;P&gt;&amp;nbsp; from sashelp.class&lt;/P&gt;&lt;P&gt;&amp;nbsp; where sex = "F";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;&amp;nbsp; create table female_only as&lt;/P&gt;&lt;P&gt;&amp;nbsp; select *&lt;/P&gt;&lt;P&gt;&amp;nbsp; from sashelp.class&lt;/P&gt;&lt;P&gt;&amp;nbsp; where sex = "F";&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 18:04:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189602#M35780</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2014-10-17T18:04:52Z</dc:date>
    </item>
    <item>
      <title>Re: help calling macro from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189603#M35781</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes I realize that. I was looking for a way around it. I guess there isn't one. I went back to the full resultset and added a column that takes out the spaces. It works now. Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 20:46:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189603#M35781</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2014-10-17T20:46:47Z</dc:date>
    </item>
    <item>
      <title>Re: help calling macro from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189604#M35782</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A __default_attr="2991" __jive_macro_name="user" class="jive_macro jive_macro_user" data-objecttype="3" href="https://communities.sas.com/"&gt;&lt;/A&gt;: If your goal was just to create the Excel files, why create SAS datasets as well? I think your macro will work fine as follows:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro exportprograms(program);&lt;/P&gt;&lt;P&gt;proc export data=prg_names1 (where=(program_name = "&amp;amp;program"))&lt;/P&gt;&lt;P&gt;&amp;nbsp; outfile="&amp;amp;destn/&amp;amp;reportnm._&amp;amp;program..xlsx"&lt;/P&gt;&lt;P&gt;&amp;nbsp; dbms=xlsx replace;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%mend exportprograms;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set prg_names1;&lt;/P&gt;&lt;P&gt;call execute('%exportprograms(program=' || program_name || ')' );&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 21:45:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189604#M35782</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2014-10-17T21:45:51Z</dc:date>
    </item>
    <item>
      <title>Re: help calling macro from data step</title>
      <link>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189605#M35783</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wondered last night if there was a way to put a where clause in proc export but then I read so many other things about other ways of doing it that I forgot about it. I like that better. Thanks. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Oct 2014 21:58:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/help-calling-macro-from-data-step/m-p/189605#M35783</guid>
      <dc:creator>dan999</dc:creator>
      <dc:date>2014-10-17T21:58:48Z</dc:date>
    </item>
  </channel>
</rss>

