<?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: SAS macro Function %STR in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340408#M77792</link>
    <description>&lt;P&gt;The %str() function call misses the closing bracket.&lt;/P&gt;</description>
    <pubDate>Mon, 13 Mar 2017 13:37:02 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2017-03-13T13:37:02Z</dc:date>
    <item>
      <title>SAS macro Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340404#M77791</link>
      <description>&lt;P&gt;I am trying to put the age into each age group by using %str function. However, I have syntax error shown as&amp;nbsp;below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The second question is it seems after I put the semi-colon after each if-then&amp;nbsp;statement, the color for the next else statement&amp;nbsp;becomes red. However, if i take away the semi-colon, the whole program didn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone have any clue about this? Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1 ;*';*";*/;quit;run;&lt;/P&gt;&lt;P&gt;______________&lt;/P&gt;&lt;P&gt;49&lt;/P&gt;&lt;P&gt;NOTE 49-169: The meaning of an identifier after a quoted string might change in a future SAS release. Inserting white space&lt;/P&gt;&lt;P&gt;between a quoted string and the succeeding identifier is recommended.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; age4=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%str&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;if age &amp;lt; 20 then group = " &amp;lt;20 ";&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; if age &amp;lt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;35&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; then group = " &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;20&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;34&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; "; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; if age &amp;lt; &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;45&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; then group = " &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;35&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;44&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt; "; &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#ff0000" face="Courier New" size="3"&gt;else&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; group = " &lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;45&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;+ " ;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;input&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; age @@;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;amp;age4;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;datalines&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;19 50 10 34 44 15 30&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;proc&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;print&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;data&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=test;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 13:27:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340404#M77791</guid>
      <dc:creator>LL5</dc:creator>
      <dc:date>2017-03-13T13:27:23Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340408#M77792</link>
      <description>&lt;P&gt;The %str() function call misses the closing bracket.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 13:37:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340408#M77792</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-13T13:37:02Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340410#M77793</link>
      <description>&lt;P&gt;You're missing a closing parenthesis and semi-colon. Try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;%let age4=%str(
if age &amp;lt; 20 then group = " &amp;lt;20 ";
else if age &amp;lt; 35 then group = " 20-34 ";
else if age &amp;lt; 45 then group = " 35-44 ";
else group = " 45+ " ;);
 
data test;
  input age @@;
  &amp;amp;age4;
  datalines;
19 50 10 34 44 15 30
;
&lt;/PRE&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 13:37:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340410#M77793</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-13T13:37:44Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340413#M77794</link>
      <description>&lt;P&gt;While you are missing that closing parenthesis in your post, I think it's likely that you included it in your actual code.&amp;nbsp; Otherwise the results would have been different.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SAS often uses a character immediately following a closing quote to change the meaning of a character string.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;"13MAR2017" ==&amp;gt; character string&lt;/P&gt;
&lt;P&gt;"13MAR2017"d ==&amp;gt; numeric SAS date&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So SAS is just warning&amp;nbsp; you that you have a character immediately following a closing quote.&amp;nbsp; You can get rid of those messages by adding a space between the closing quotes and the statement-ending semicolons.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 13:41:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340413#M77794</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-03-13T13:41:31Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340415#M77795</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;: the NOTE 49-169 often happens when the "magic closing string" sent by EG catches anything unbalanced and subsequently creates a quote-immediately-followed-by-something-else situation by itself.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 13:45:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340415#M77795</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-03-13T13:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340417#M77796</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The %LET statement ends with the first semi-colon and so, you are using both %LET and %STR in a way that is going to cause you problems. Putting an entire code snippet into a macro variable isn't the best idea. Using %INCLUDE for complete code snippets or a small macro program are better choices.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; But, I'm not sure why you even want to use a macro variable for your creation of the GROUP variable. You can easily do what you want with a user defined format....no macro needed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;cynthia&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This program and output requires no macro code at all.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value grpf low-13 = ' &amp;lt;14'
             14-15 = '14-15'
	     16-high = '16-high';
run;

data test;
infile datalines dlm=',';
input name $ age  ;
group = put(age,grpf.);
return;
datalines;
Alan,12 
Barb,11
Carl,13
Dave,15
Eliza,15 
Frank,16
Gina,17
Hal,18
Inez,19
John,20
Kay,21
Louise,12 
Mike,14
Norma,14
Oona,15 
;
run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and produces:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/7685iBA3C2F68E15D55B3/image-size/original?v=1.0&amp;amp;px=-1" alt="with_format.png" title="with_format.png" border="0" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Mar 2017 13:47:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340417#M77796</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2017-03-13T13:47:09Z</dc:date>
    </item>
    <item>
      <title>Re: SAS macro Function %STR</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340422#M77798</link>
      <description>&lt;P&gt;Why are you putting SAS code into a macro variable, that doesn't sound like a good way to proceed. &amp;nbsp;You could just setup a format for that condition, several other better methods.&lt;/P&gt;
&lt;PRE&gt;proc format;&lt;BR /&gt; value agefmt&lt;BR /&gt; low-20 = "&amp;lt;20"&lt;BR /&gt; 21-35 = "20-34";&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data test;&lt;BR /&gt; input age @@;&lt;BR /&gt; format age agefmt.;&lt;BR /&gt;datalines;&lt;BR /&gt;19 50 10 34 44 15 30&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 13 Mar 2017 14:09:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SAS-macro-Function-STR/m-p/340422#M77798</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-03-13T14:09:45Z</dc:date>
    </item>
  </channel>
</rss>

