<?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: Problems using %str in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396275#M95652</link>
    <description>&lt;P&gt;You are complicating your program (and the possibility for errors) by adding pieces you don't need. &amp;nbsp;This statement would work without %STR (as long as you use double-quotes):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let fich2 = "&amp;amp;fich";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact, you could skip creating &amp;amp;FICH2 entirely:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let val&amp;nbsp;= %str(data coches; set coches; fichero = "&amp;amp;fich"; run; ) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's possible that this fixes everything. &amp;nbsp;But if it doesn't, I'm expecting that %PUT would still work. &amp;nbsp;Only the code execution needs to be changed. &amp;nbsp;If this is the final step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;val&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to change it to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%unquote(&amp;amp;val)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's likely you won't need %UNQUOTE in this particular case (I can't test it right now), but might need it if you were generating SQL code instead of a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;SIde note: &amp;nbsp;In the solution that you accepted, check the value of FICHERO. &amp;nbsp;I suspect it contains extra characters.&lt;/P&gt;</description>
    <pubDate>Fri, 15 Sep 2017 11:20:00 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-09-15T11:20:00Z</dc:date>
    <item>
      <title>Problems using %str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396243#M95643</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am getting problems using %str.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When i do:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let val = %str(data coches; set sashelp.cars; run);

%put val = &amp;amp;val.;

&amp;amp;val.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it works properly, but now I make a modification:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fich = cars;

%let fich2 = %str(%")&amp;amp;fich%str(%");

%let val  = %str(data coches; set coches; fichero = &amp;amp;fich2 ;run;);

%put val = &amp;amp;val.;

&amp;amp;val.;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;it doesn' work in the put stament I can see the macrovaroable well created&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; %put val = &amp;amp;val.;
val = data coches; set coches; fichero = "cars" ;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;but when I invoke tha macrovariable to execute de the data steps with errors:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;23         &amp;amp;val.;
180: LINE y COLUMN no se pueden determinar.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 180-322: Statement is not valid or it is used out of proper order.

           _
           386
           200
ERROR 386-185: Expecting an arithmetic expression.

ERROR 200-322: The symbol is not recognized and will be ignored.

24         
25         GOPTIONS NOACCESSIBLE;
26         %LET _CLIENTTASKLABEL=;
27         %LET _CLIENTPROJECTPATH=;
28         %LET _CLIENTPROJECTNAME=;
29         %LET _SASPROGRAMFILE=;
30         
31         ;*';*";*/;quit;run;
                     ____
                     180

ERROR 180-322: Statement is not valid or it is used out of proper order.

NOTE: The SAS System stopped processing this step because of errors.&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anybody help me??&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 10:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396243#M95643</guid>
      <dc:creator>juanvg1972</dc:creator>
      <dc:date>2017-09-15T10:36:48Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using %str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396247#M95644</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/52605"&gt;@juanvg1972&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Try...&lt;/P&gt;
&lt;PRE&gt;%put val = %unquote(&amp;amp;val.);&lt;/PRE&gt;
&lt;P&gt;...and let us know if that helped.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 10:47:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396247#M95644</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-09-15T10:47:05Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using %str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396249#M95645</link>
      <description>&lt;P&gt;You need to put double quotes around &amp;amp;fich2 in order to force resolution of the macro variable when val is assigned like so&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let fich = cars;

%let fich2 = %str(%")&amp;amp;fich%str(%");

%let val  = %str(data coches; set coches; fichero = "&amp;amp;fich2" ;run;);

%put val = &amp;amp;val.;

&amp;amp;val.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 15 Sep 2017 10:48:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396249#M95645</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-15T10:48:19Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using %str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396258#M95649</link>
      <description>&lt;P&gt;The masking functions add tokens to the strings that are recognized by the macro processor, but will confuse the main SAS interpreter.&lt;/P&gt;
&lt;P&gt;Bottom line: don't add quotes in macro variables, put them around the macro variables in the data step. A situation where you don't know beforehand if a variable is character or numeric is strongly advised against. Such constructs will bite you in the behind as soon as you turn your back on them.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 11:02:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396258#M95649</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-09-15T11:02:28Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using %str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396275#M95652</link>
      <description>&lt;P&gt;You are complicating your program (and the possibility for errors) by adding pieces you don't need. &amp;nbsp;This statement would work without %STR (as long as you use double-quotes):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let fich2 = "&amp;amp;fich";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In fact, you could skip creating &amp;amp;FICH2 entirely:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let val&amp;nbsp;= %str(data coches; set coches; fichero = "&amp;amp;fich"; run; ) ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's possible that this fixes everything. &amp;nbsp;But if it doesn't, I'm expecting that %PUT would still work. &amp;nbsp;Only the code execution needs to be changed. &amp;nbsp;If this is the final step:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;val&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You may need to change it to:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%unquote(&amp;amp;val)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It's likely you won't need %UNQUOTE in this particular case (I can't test it right now), but might need it if you were generating SQL code instead of a DATA step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;SIde note: &amp;nbsp;In the solution that you accepted, check the value of FICHERO. &amp;nbsp;I suspect it contains extra characters.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 11:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396275#M95652</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-15T11:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using %str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396280#M95656</link>
      <description>&lt;P&gt;Nobody questioning the bizarre use of Base SAS in a macro variable? &amp;nbsp;I would go mad if I saw that in any code I had to deal with. &amp;nbsp;Base SAS if the programming language, macro is only there to help generate some it, it is not for anything else.&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 11:36:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396280#M95656</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-15T11:36:13Z</dc:date>
    </item>
    <item>
      <title>Re: Problems using %str</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396318#M95671</link>
      <description>&lt;P&gt;I agree absolutely&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/45151"&gt;@RW9&lt;/a&gt;&amp;nbsp;- as it stands there's no reason to be doing what the OP posted and every reason not to do it that way. I took it as an exercise in understanding how macro variable resolution works. I too would be less than happy seeing something like that in production code.......&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 13:34:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problems-using-str/m-p/396318#M95671</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-15T13:34:47Z</dc:date>
    </item>
  </channel>
</rss>

