<?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 Removing space while resolving macros in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127443#M260313</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;input cprno$ ;&lt;BR /&gt;datalines;&lt;BR /&gt;CPR006&lt;BR /&gt;CPR081&lt;BR /&gt;CPR015&lt;BR /&gt;CPR022&lt;BR /&gt;CPR103&lt;BR /&gt;CPR127&lt;BR /&gt;CPR136&lt;BR /&gt;CPR036&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;create table CPR as select distinct CPRNO&lt;BR /&gt;from test;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;select CPRNO&lt;BR /&gt;into : CPRNO&lt;BR /&gt;from CPR;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;select count(distinct CPRNO)&lt;BR /&gt;into :numrows&lt;BR /&gt;from CPR;&lt;BR /&gt;quit;&lt;BR /&gt;%let numrows=&amp;amp;numrows;&lt;BR /&gt;%put numrows=&amp;amp;numrows;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro CPRNUM;&lt;BR /&gt;proc sort data=CPR out=temperv nodupkey;&lt;BR /&gt;by CPRNO;&lt;BR /&gt;run;&lt;BR /&gt;data _null_;&lt;BR /&gt;set temperv end=eof;&lt;BR /&gt;call symput('CPRNO'!!left(put(_n_,10.)),CPRNO);&lt;BR /&gt;if eof then&lt;BR /&gt;call symput('numrows',left(put(_n_,20.)));&lt;BR /&gt;run;&lt;BR /&gt;%put _user_;&lt;/P&gt;&lt;P&gt;%do i= 1 %to &amp;amp;numrows;&lt;BR /&gt;/*Connecting to oracle and executing procedure fetching the final table */&lt;BR /&gt;proc sql;&lt;BR /&gt;connect to oracle(user=developer password="&amp;amp;dbpass" path='cprdev');&lt;BR /&gt;execute (execute PROCEDURE_CHECK("&amp;amp;&amp;amp;CPRNO&amp;amp;i")) by oracle;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; create table FUN as select * from connection to oracle(select * from CPR_LOG_FINAL ) ;&lt;BR /&gt; disconnect from oracle;&lt;BR /&gt;quit;&lt;BR /&gt; %end;&lt;BR /&gt; %MEND CPRNUM;&lt;BR /&gt; %cprnum;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i am passing cprno as parameter and executing procedure&lt;/P&gt;&lt;P&gt;while executing procedure i am getting error&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;identifier 'CPR006&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' too long.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i am passing 'CPR006' (ie., hard coding ) i am able to execute procedure&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how to remove this space while execution &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 May 2013 05:17:13 GMT</pubDate>
    <dc:creator>santhosh</dc:creator>
    <dc:date>2013-05-02T05:17:13Z</dc:date>
    <item>
      <title>Removing space while resolving macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127443#M260313</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am using the following code&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;BR /&gt;input cprno$ ;&lt;BR /&gt;datalines;&lt;BR /&gt;CPR006&lt;BR /&gt;CPR081&lt;BR /&gt;CPR015&lt;BR /&gt;CPR022&lt;BR /&gt;CPR103&lt;BR /&gt;CPR127&lt;BR /&gt;CPR136&lt;BR /&gt;CPR036&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;create table CPR as select distinct CPRNO&lt;BR /&gt;from test;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;select CPRNO&lt;BR /&gt;into : CPRNO&lt;BR /&gt;from CPR;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;proc sql ;&lt;BR /&gt;select count(distinct CPRNO)&lt;BR /&gt;into :numrows&lt;BR /&gt;from CPR;&lt;BR /&gt;quit;&lt;BR /&gt;%let numrows=&amp;amp;numrows;&lt;BR /&gt;%put numrows=&amp;amp;numrows;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro CPRNUM;&lt;BR /&gt;proc sort data=CPR out=temperv nodupkey;&lt;BR /&gt;by CPRNO;&lt;BR /&gt;run;&lt;BR /&gt;data _null_;&lt;BR /&gt;set temperv end=eof;&lt;BR /&gt;call symput('CPRNO'!!left(put(_n_,10.)),CPRNO);&lt;BR /&gt;if eof then&lt;BR /&gt;call symput('numrows',left(put(_n_,20.)));&lt;BR /&gt;run;&lt;BR /&gt;%put _user_;&lt;/P&gt;&lt;P&gt;%do i= 1 %to &amp;amp;numrows;&lt;BR /&gt;/*Connecting to oracle and executing procedure fetching the final table */&lt;BR /&gt;proc sql;&lt;BR /&gt;connect to oracle(user=developer password="&amp;amp;dbpass" path='cprdev');&lt;BR /&gt;execute (execute PROCEDURE_CHECK("&amp;amp;&amp;amp;CPRNO&amp;amp;i")) by oracle;&lt;BR /&gt;&amp;nbsp;&amp;nbsp; create table FUN as select * from connection to oracle(select * from CPR_LOG_FINAL ) ;&lt;BR /&gt; disconnect from oracle;&lt;BR /&gt;quit;&lt;BR /&gt; %end;&lt;BR /&gt; %MEND CPRNUM;&lt;BR /&gt; %cprnum;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;i am passing cprno as parameter and executing procedure&lt;/P&gt;&lt;P&gt;while executing procedure i am getting error&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000; font-size: 12pt; font-family: Courier New;"&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #ff0000;"&gt;identifier 'CPR006&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;&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' too long.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if i am passing 'CPR006' (ie., hard coding ) i am able to execute procedure&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;how to remove this space while execution &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2013 05:17:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127443#M260313</guid>
      <dc:creator>santhosh</dc:creator>
      <dc:date>2013-05-02T05:17:13Z</dc:date>
    </item>
    <item>
      <title>Re: Removing space while resolving macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127444#M260314</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello santhosh, I think this is a simple solution you could try...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set temperv end=eof;&lt;/P&gt;&lt;P&gt;length t_str $100.;&lt;/P&gt;&lt;P&gt;t_str = cats('CPRNO',put(_n_,10.));&lt;/P&gt;&lt;P&gt;call symput(t_str,CPRNO);&lt;/P&gt;&lt;P&gt;if eof then&lt;/P&gt;&lt;P&gt;t_str = left(put(_n_,20.));&lt;/P&gt;&lt;P&gt;call symput('numrows',t_str);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;%put _user_;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2013 10:44:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127444#M260314</guid>
      <dc:creator>TimArm</dc:creator>
      <dc:date>2013-05-02T10:44:22Z</dc:date>
    </item>
    <item>
      <title>Re: Removing space while resolving macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127445#M260315</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;There is a %TRIM() function which can be used in your existing code&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;execute (execute PROCEDURE_CHECK("%TRIM(&amp;amp;&amp;amp;CPRNO&amp;amp;i)")) by oracle;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Another simpler way to trim a macro variable (including leading spaces) is&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let mvalue = &amp;amp;mvalue ;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;but this is not practical in your code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;Richard&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2013 10:50:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127445#M260315</guid>
      <dc:creator>RichardinOz</dc:creator>
      <dc:date>2013-05-02T10:50:02Z</dc:date>
    </item>
    <item>
      <title>Re: Removing space while resolving macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127446#M260316</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Santhosh,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To trim macro variables &lt;STRONG&gt;%trim&lt;/STRONG&gt; and&lt;STRONG&gt; %left&lt;/STRONG&gt; function can be used to remove trailing and leading space.&lt;/P&gt;&lt;P&gt;But In general, while the macro variable is created it does'nt store leading or trailing space in it .&lt;/P&gt;&lt;P&gt;%let test =&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;&amp;nbsp;&amp;nbsp;&amp;nbsp; hi&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;%put &amp;amp;test;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline;"&gt;output: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;hi&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But in your case, you are assigning macro variable 'CPRNO' via datastep and the dataset variable CPRNO may contain leading or trailing space. &lt;/P&gt;&lt;P&gt;So try the below code.&amp;nbsp; &lt;/P&gt;&lt;P&gt;call symput('CPRNO'!!left(put(_n_,10.)),&lt;STRONG style="text-decoration: underline;"&gt;strip(CPRNO&lt;/STRONG&gt;));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2013 12:18:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127446#M260316</guid>
      <dc:creator>suraestar</dc:creator>
      <dc:date>2013-05-02T12:18:39Z</dc:date>
    </item>
    <item>
      <title>Re: Removing space while resolving macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127447#M260317</link>
      <description>&lt;P&gt;&lt;EM&gt;Editor's note: Alot of great solutions that&amp;nbsp;will work but Ksharp has the easiest with using CALL SYMPUTX.&amp;nbsp; This call routine will trim any leading or trailing blanks that may be in the value.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;use&amp;nbsp; call symput&lt;STRONG&gt;x&lt;/STRONG&gt; () ;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Aug 2017 18:08:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127447#M260317</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-08-14T18:08:47Z</dc:date>
    </item>
    <item>
      <title>Re: Removing space while resolving macros</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127448#M260318</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Nice one Ksharp. I will use that in future.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Tim&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2013 12:42:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Removing-space-while-resolving-macros/m-p/127448#M260318</guid>
      <dc:creator>TimArm</dc:creator>
      <dc:date>2013-05-02T12:42:30Z</dc:date>
    </item>
  </channel>
</rss>

