<?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: Macro questions on excel in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623248#M19904</link>
    <description>&lt;P&gt;It doesn't feel right to create that many tables - but here you go.&lt;/P&gt;
&lt;P&gt;The hash output method allows to create tables during execution time which makes this a simple task.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input (no name country) ($);
  datalines;
raw1 jasper Japan
raw2 Peter France
raw3 Ben England
raw4 Harry USA
raw4 Peter USA
raw5 Henry China
12raw5 Henry China
;

proc sort data=have;
  by no;
run;

data _null_;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(obs=0)', multidata:'y', hashexp:3);
      h1.defineKey('name');
      h1.defineData(all:'y');
      h1.defineDone();
    end;

  set have;
  by no;
  h1.add();

  if last.no then
    do;
      h1.output(dataset:no);
      h1.clear();
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 08 Feb 2020 01:52:11 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2020-02-08T01:52:11Z</dc:date>
    <item>
      <title>Macro questions on excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/622990#M19866</link>
      <description>&lt;P&gt;hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;here is my script&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%Macro testing(A=,B=,C=);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table &amp;amp;A as&lt;/P&gt;&lt;P&gt;select * from raw_file&lt;BR /&gt;where name like &amp;amp;B&lt;/P&gt;&lt;P&gt;and country in &amp;amp;C&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;P&gt;%Testing(A=RAW1,B="%Jasper%",C="Japan");&lt;/P&gt;&lt;P&gt;%Testing(A=RAW2,B="%Peter%",C="France");&lt;/P&gt;&lt;P&gt;%Testing(A=RAW3,B="%Ben%",C="England");&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;the problem is i have a long list from excel which contains people name and country&lt;/P&gt;&lt;P&gt;so do i have to type the name and country one by one under the %mend in SAS?&lt;/P&gt;&lt;P&gt;if i got 10000 records ,then should i input 10000 scripts in this SAS program?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;can i just write a macro program so that the program can read the data from excel?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my excel format:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;No .&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Name&amp;nbsp; &amp;nbsp; &amp;nbsp;Country&lt;/P&gt;&lt;P&gt;&amp;nbsp;raw1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; jasper&amp;nbsp; &amp;nbsp; Japan&lt;/P&gt;&lt;P&gt;&amp;nbsp;raw2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Peter&amp;nbsp; &amp;nbsp; &amp;nbsp; France&lt;/P&gt;&lt;P&gt;&amp;nbsp;raw3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Ben&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; England&lt;/P&gt;&lt;P&gt;&amp;nbsp;raw4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Harry&amp;nbsp; &amp;nbsp; &amp;nbsp; USA&lt;/P&gt;&lt;P&gt;&amp;nbsp;raw5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Henry&amp;nbsp; &amp;nbsp; &amp;nbsp;China&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you all&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 09:56:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/622990#M19866</guid>
      <dc:creator>harrylui</dc:creator>
      <dc:date>2020-02-07T09:56:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro questions on excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/622994#M19867</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/107435"&gt;@harrylui&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a way to achieve this.&lt;/P&gt;
&lt;P&gt;NB: I suggest that you use the FIND() function in your proc sql to avoid issues with the %.&lt;/P&gt;
&lt;P&gt;When you invoke the macro %testing, no need to use "" to specify the values of A, B and C.&lt;/P&gt;
&lt;P&gt;Best,&lt;/P&gt;
&lt;P&gt;/*UNTESTED CODE*/&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Import your data from Excel - proc import */

data excel_file;
	input No $ Name $ Country $;
	datalines;
raw1 jasper Japan
raw2 Peter France
raw3 Ben England
raw4 Harry USA
raw5 Henry China
;
run;

%Macro testing(A=,B=,C=);
 
	proc sql;
		create table &amp;amp;A as
		select * from raw_file
		where find(upcase(name),upcase("&amp;amp;B"))
		  	  and find(upcase(country), upcase("&amp;amp;C"));
	quit;
%mend;

%Testing(A=RAW1,B=Jasper,C=Japan);

/*Drive the macro execution througt data - DOSUBL function or CALL EXECUTE*/

data _null_;
	set excel_file;
	rc = dosubl(cats('%Testing(A=',No,', B=',Name,', C=',Country,')'));
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 10:12:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/622994#M19867</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-07T10:12:57Z</dc:date>
    </item>
    <item>
      <title>Re: Macro questions on excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/622997#M19868</link>
      <description>&lt;P&gt;Here is the documentation about the DOSUBL() function:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p09dcftd1xxg1kn1brnjyc0q93yk.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_self"&gt;https://documentation.sas.com/?docsetId=lefunctionsref&amp;amp;docsetTarget=p09dcftd1xxg1kn1brnjyc0q93yk.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 10:14:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/622997#M19868</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-07T10:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro questions on excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623010#M19871</link>
      <description>&lt;P&gt;The first thing you should check: do you really need a dataset for each row in your excel-file? What do you do with all those datasets? And what do you mean by "and country in &amp;amp;C"? &lt;/P&gt;</description>
      <pubDate>Fri, 07 Feb 2020 11:17:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623010#M19871</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2020-02-07T11:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Macro questions on excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623248#M19904</link>
      <description>&lt;P&gt;It doesn't feel right to create that many tables - but here you go.&lt;/P&gt;
&lt;P&gt;The hash output method allows to create tables during execution time which makes this a simple task.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input (no name country) ($);
  datalines;
raw1 jasper Japan
raw2 Peter France
raw3 Ben England
raw4 Harry USA
raw4 Peter USA
raw5 Henry China
12raw5 Henry China
;

proc sort data=have;
  by no;
run;

data _null_;
  if _n_=1 then
    do;
      dcl hash h1(dataset:'have(obs=0)', multidata:'y', hashexp:3);
      h1.defineKey('name');
      h1.defineData(all:'y');
      h1.defineDone();
    end;

  set have;
  by no;
  h1.add();

  if last.no then
    do;
      h1.output(dataset:no);
      h1.clear();
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 08 Feb 2020 01:52:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623248#M19904</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2020-02-08T01:52:11Z</dc:date>
    </item>
    <item>
      <title>Re: Macro questions on excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623305#M19911</link>
      <description>&lt;P&gt;To generate code from data I find it much easier to generate the code to a text file. That way I can examine the file and make sure I have the generation logic correct. I can copy the first example from the file and run it to test it.&lt;/P&gt;
&lt;P&gt;First let's make a dataset that looks like your Excel file.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input No_ :$32. Name &amp;amp;:$50. Country &amp;amp;:$50.;
cards;
raw1   jasper   Japan
raw2   Peter    France
raw3   Ben      England
raw4   Harry    USA
raw5   Henry    China
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now we can write a data _null_ step to create the macro calls from that data.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename code temp;
data _null_;
  file code;
  set have;
  length a b c $100;
  a=No_ ;
  b=quote(cats('%',name,'%'),"'");
  c=quote(trim(country));
  put '%testing(' a= ',' b= ',' c= ');' ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So the resulting file will look like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%testing(a=raw1 ,b='%jasper%' ,c="Japan" );
%testing(a=raw2 ,b='%Peter%' ,c="France" );
%testing(a=raw3 ,b='%Ben%' ,c="England" );
%testing(a=raw4 ,b='%Harry%' ,c="USA" );
%testing(a=raw5 ,b='%Henry%' ,c="China" );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then to run the generated calls just use %INCLUDE statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include code / source2;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 08 Feb 2020 16:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623305#M19911</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-02-08T16:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Macro questions on excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623475#M19931</link>
      <description>&lt;P&gt;thanks&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 02:19:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623475#M19931</guid>
      <dc:creator>harrylui</dc:creator>
      <dc:date>2020-02-10T02:19:53Z</dc:date>
    </item>
    <item>
      <title>Re: Macro questions on excel</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623476#M19932</link>
      <description>&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 10 Feb 2020 02:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Macro-questions-on-excel/m-p/623476#M19932</guid>
      <dc:creator>harrylui</dc:creator>
      <dc:date>2020-02-10T02:20:12Z</dc:date>
    </item>
  </channel>
</rss>

