<?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 use macro along with into:? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341840#M78301</link>
    <description>New knowledge on that automatic trimming and the fact that the macro has leading and trailing blanks built in. I wish my company starts using other modern languages &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Fri, 17 Mar 2017 02:29:10 GMT</pubDate>
    <dc:creator>afiqcjohari</dc:creator>
    <dc:date>2017-03-17T02:29:10Z</dc:date>
    <item>
      <title>How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341456#M78159</link>
      <description>&lt;P&gt;I want to determine in advance the number of distinct items and create as many macro variables as the number of items.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*get the number of distinct cPOSMode;
proc sql;
	select count(distinct cPOSMode) into :cPOSModeCNT
	from have;
quit;

*generate the macro variables based on the previous number;
proc sql;
 select distinct cPOSMode 
 into :cPOSMode1-:cPOSMode&amp;amp;cPOSModeCNT.
 from have;
 quit;&lt;/PRE&gt;&lt;P&gt;Any tips on this?&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 08:03:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341456#M78159</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-16T08:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341468#M78165</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use a data step :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _NULL_;
    set have;
    call symput(cats("cPosMode",_N_),cPosMode);
    call symput("cPosModeCNT",_N_);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Edit : use a prior proc sort with nodupkey to eliminate duplicates. &lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 08:35:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341468#M78165</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-03-16T08:35:25Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341472#M78169</link>
      <description>&lt;P&gt;See my anser in the other thread:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*get the number of distinct cPOSMode;
proc sql;
	select count(distinct cPOSMode) into :cPOSModeCNT
	from have;
quit;

%let cPOSModeCNT=%sysfunc(strip(&amp;amp;cPOSModeCNT));

*generate the macro variables based on the previous number;
proc sql;
 select distinct cPOSMode 
 into :cPOSMode1-:cPOSMode&amp;amp;cPOSModeCNT.
 from have;
 quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The select into formats the number, causing leading blanks that have to be removed.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 08:42:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341472#M78169</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-16T08:42:58Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341473#M78170</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Before we use a macro value obtained from SQL we need to trim the blanks.&lt;/P&gt;&lt;P&gt;That is, Macro Variable : cPOSModeCNT would have leading and trailing blanks which needs to be taken off before we use it alongside a literal.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The code should work with this small change as below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;*get the number of distinct cPOSMode;
proc sql;
	select count(distinct cPOSMode) into :cPOSModeCNT
	from have;
quit;
&lt;BR /&gt;&lt;STRONG&gt;%let cPOSModeCNT=&amp;amp;cPOSModeCNT;&lt;/STRONG&gt;&lt;BR /&gt;
*generate the macro variables based on the previous number;
proc sql;
 select distinct cPOSMode 
 into :cPOSMode1-:cPOSMode&amp;amp;cPOSModeCNT.
 from have;
 quit;&lt;/PRE&gt;&lt;P&gt;I hope this would be helpful.&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;GP&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 08:43:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341473#M78170</guid>
      <dc:creator>GPNaveen</dc:creator>
      <dc:date>2017-03-16T08:43:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341474#M78171</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/133983"&gt;@GPNaveen&lt;/a&gt; just showed me that I was thinking much too complicated! Kudos.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 08:45:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341474#M78171</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-16T08:45:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341475#M78172</link>
      <description>&lt;P&gt;But the question still remains: what will be done with that macro variable list?&lt;/P&gt;
&lt;P&gt;In &amp;gt;90% of cases, this is better handled with by-group processing. And if one needs to iterate through a list of values, keeping them in a dataset and using call execute from that will be the option of choice.&lt;/P&gt;
&lt;P&gt;The less macro logic you need to employ in your code, the better. Data step code is much easier to maintain than macro code.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 08:48:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341475#M78172</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-16T08:48:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341490#M78179</link>
      <description>&lt;P&gt;I have to agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;here. &amp;nbsp;This is something we see on these forums on a day to day basis, and in work all the time as well. &amp;nbsp;Macro language is&amp;nbsp;&lt;STRONG&gt;not&lt;/STRONG&gt; a replacement for Base SAS programming. &amp;nbsp;When you are finding that you are writing lots of macro code, then you are simply creating work for yourself and making unmanageable code. &amp;nbsp;Lets examine your example. &amp;nbsp;How many cposmodecnt's are we talking about, with a big dataset this could run to millions. &amp;nbsp;Are they all going to valid for macro paratmeters, i.e. conform to SAS naming conventions, what happens if there are globla macro variables setup for these - as you have no control over what is created there, what about other macro processes? &amp;nbsp;&lt;/P&gt;
&lt;P&gt;In all cases there is far simpler base code which will achieve the same result - as remember macro does nothing, it just creates some base code - utilise data modelling techinques e.g. re-structure your data, use inbuilt base SAS by group processing, use inbuilt variable lists or arrays etc.&lt;/P&gt;
&lt;P&gt;Whilst i understand that the above advice will be ignored, just remember that one day you will be the person coming into a job and seeing this, and for me this would be a delete key jobbie.&lt;/P&gt;</description>
      <pubDate>Thu, 16 Mar 2017 09:20:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341490#M78179</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-16T09:20:48Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341524#M78196</link>
      <description>&lt;PRE&gt;
proc sql;
	select count(distinct cPOSMode) into :cPOSModeCNT  separated by ' '
	from have;

 select distinct cPOSMode 
 into :cPOSMode1-:cPOSMode&amp;amp;cPOSModeCNT.
 from have;
 quit;

&lt;/PRE&gt;</description>
      <pubDate>Thu, 16 Mar 2017 10:49:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341524#M78196</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-03-16T10:49:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341836#M78298</link>
      <description>&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, What do you mean by by-group processing? Are you referring to the executing the different values from a dataset?</description>
      <pubDate>Fri, 17 Mar 2017 02:20:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341836#M78298</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-17T02:20:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341839#M78300</link>
      <description>I'm open to the workflow ideas as I'm new to SAS, having abandoned it for years but the current job is using a legacy system which has SAS on top of it.&lt;BR /&gt;&lt;BR /&gt;I only see macro language as the medium for me to give some modularity to the work. Though I maybe wrong as I'm not that aware of things like what is a valid macro parameters for example.&lt;BR /&gt;&lt;BR /&gt;Having said that, if you have something for me to read on best practices to write SAS code, I'd be very interested to learn more.</description>
      <pubDate>Fri, 17 Mar 2017 02:26:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341839#M78300</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-17T02:26:40Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341840#M78301</link>
      <description>New knowledge on that automatic trimming and the fact that the macro has leading and trailing blanks built in. I wish my company starts using other modern languages &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Fri, 17 Mar 2017 02:29:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341840#M78301</guid>
      <dc:creator>afiqcjohari</dc:creator>
      <dc:date>2017-03-17T02:29:10Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341847#M78306</link>
      <description>&lt;P&gt;You do not need to count the number in advance. Let SAS count for you if you need the count.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql noprint;
  select distinct cPOSMode 
    into :cPOSMode1-
    from have
  ;
%let cPOSModeCNT=&amp;amp;sqlobs ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you are using an old version of SAS then just give it a upper bound that is larger than any value you will encounter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;    into :cPOSMode1-:cPOSMode99999&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;As to code to eliminate generating macro "arrays" it just depends on what you are actually doing. Some things can easily be done using BY statement.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway ;
   class cPOSMOde ;
....&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or pernaps:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data xx ;
  set have ;
  by cPOSmode ;
  if first.cPOSMode .....
  ...
  if last.cPOSMode ....
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 17 Mar 2017 03:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341847#M78306</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-03-17T03:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: How to use macro along with into:?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341872#M78320</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/130031"&gt;@afiqcjohari&lt;/a&gt; wrote:&lt;BR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;, What do you mean by by-group processing? Are you referring to the executing the different values from a dataset?&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I already gave you an answer to that question in&amp;nbsp;&lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/How-to-create-a-list-of-macro-variables-using-proc-SQL/m-p/341449#M78153" target="_blank"&gt;https://communities.sas.com/t5/Base-SAS-Programming/How-to-create-a-list-of-macro-variables-using-proc-SQL/m-p/341449#M78153&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Mar 2017 06:08:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-use-macro-along-with-into/m-p/341872#M78320</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-17T06:08:59Z</dc:date>
    </item>
  </channel>
</rss>

