<?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 variable not resolving correctly in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216273#M39860</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest simplifying this line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let varName =%qscan(%sysfunc(compbl(&amp;amp;numvar)),&amp;amp;i,%str( ));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This would be sufficient, since blanks are the only delimiters that might be found in a list of normal variable names:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let varName =%scan(&amp;amp;numvar,&amp;amp;i);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's conceivable that the quoting character introduced by %QSCAN causes a problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this doesn't work, you'll need to show your real code.&amp;nbsp; We know that a %DO statement with no matching %END is different than your actual code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 29 Jun 2015 20:51:59 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2015-06-29T20:51:59Z</dc:date>
    <item>
      <title>Macro variable not resolving correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216270#M39857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am in the process of building a macro. The code is shown below.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have concatenated macro variables with some prefix (sqrt_ for square roots etc). When i ask to print using %put, it is showing macro variable with concatenated text correctly. However, when i use it in PROC LOGISTIC, it returns " sqrt_ not found" error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;%let varName =%qscan(%sysfunc(compbl(&amp;amp;numvar)),&amp;amp;i,%str( ));&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;%let srtvar1 = sqrt_&amp;amp;varName.;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;%put &amp;amp;varName. &amp;amp;srtvar1.;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;options&amp;nbsp; symbolgen;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;ODS OUTPUT EFFECTNOTINMODEL = Estimate&amp;amp;i.;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;PROC LOGISTIC DATA = &amp;amp;output. DESC;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;MODEL &amp;amp;depvar. = &amp;amp;varName. &amp;amp;srtvar1.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;/ SELECTION = S MAXSTEP = 1 DETAILS;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;RUN;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px;"&gt;&lt;STRONG&gt;Detailed Code :&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%macro test(input = ,depvar=, output=);&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symput ("library", put(upcase(substr("&amp;amp;input",1,index("&amp;amp;input",'.')-1)), $8.));&lt;/P&gt;&lt;P&gt;call symput ("datset", put(upcase(substr("&amp;amp;input",index("&amp;amp;input",'.')+1,length("&amp;amp;input"))), $32.));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Selecting numeric variables;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;/P&gt;&lt;P&gt;select name into : numvar separated by " "&lt;/P&gt;&lt;P&gt;from dictionary.columns&lt;/P&gt;&lt;P&gt;where LIBNAME = "&amp;amp;library"&lt;/P&gt;&lt;P&gt;and MEMNAME = "PREDATA"&lt;/P&gt;&lt;P&gt;and type = 'num';&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let varn=%sysfunc(countw(&amp;amp;numvar%str( )));&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;*Run for all the numeric variables;&lt;/P&gt;&lt;P&gt;%DO i=1 %TO &amp;amp;varn;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;*Selecting Variable one by one;&lt;/P&gt;&lt;P&gt;%let varName =%qscan(%sysfunc(compbl(&amp;amp;numvar)),&amp;amp;i,%str( ));&lt;/P&gt;&lt;P&gt;%let srtvar1 = sqrt_&amp;amp;varName.;&lt;/P&gt;&lt;P&gt;%let sqvar1&amp;nbsp; = sq_&amp;amp;varName.;&lt;/P&gt;&lt;P&gt;%let logvar1 = log_&amp;amp;varName.;&lt;/P&gt;&lt;P&gt;%let invvar1 = inv_&amp;amp;varName.;&lt;/P&gt;&lt;P&gt;%let cbvar1&amp;nbsp; = cb_&amp;amp;varName.;&lt;/P&gt;&lt;P&gt;%let cbrtvar1= cbrt_&amp;amp;varName.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%put &amp;amp;varName. &amp;amp;srtvar1.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;options&amp;nbsp; symbolgen;&lt;/P&gt;&lt;P&gt;ODS OUTPUT EFFECTNOTINMODEL = Estimate&amp;amp;i.;&lt;/P&gt;&lt;P&gt;PROC LOGISTIC DATA = &amp;amp;output. DESC;&lt;/P&gt;&lt;P&gt;MODEL &amp;amp;depvar. = &amp;amp;varName. &amp;amp;srtvar1. &amp;amp;sqvar1. &amp;amp;logvar1. &amp;amp;invvar1. &amp;amp;cbvar1. &amp;amp;cbrtvar1.&lt;/P&gt;&lt;P&gt;/ SELECTION = S MAXSTEP = 1 DETAILS;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;options&amp;nbsp; nosymbolgen;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%mend;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Jun 2015 18:46:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216270#M39857</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2015-06-29T18:46:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolving correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216271#M39858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;examine the data structure of your input data and verify the presence of the variable names you are seeking&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql; describe table &amp;amp;data;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Jun 2015 19:42:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216271#M39858</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-06-29T19:42:33Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolving correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216272#M39859</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Variables are in the file. Still it is throwing error -"Sqrt_ not found". If you look at error - It is not saying - "Sqrt_Height" not found.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Jun 2015 20:15:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216272#M39859</guid>
      <dc:creator>Ujjawal</dc:creator>
      <dc:date>2015-06-29T20:15:34Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolving correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216273#M39860</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I would suggest simplifying this line:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let varName =%qscan(%sysfunc(compbl(&amp;amp;numvar)),&amp;amp;i,%str( ));&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This would be sufficient, since blanks are the only delimiters that might be found in a list of normal variable names:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%let varName =%scan(&amp;amp;numvar,&amp;amp;i);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It's conceivable that the quoting character introduced by %QSCAN causes a problem.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If this doesn't work, you'll need to show your real code.&amp;nbsp; We know that a %DO statement with no matching %END is different than your actual code.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Jun 2015 20:51:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216273#M39860</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2015-06-29T20:51:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolving correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216274#M39861</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The value of macro variable SRTVAR1 is being treated as two tokens because of the macro quoting.&lt;/P&gt;&lt;P&gt;You should not need to use %QSCAN() since you are using the result as part of a variable name.&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let varName =%SCAN(%sysfunc(compbl(&amp;amp;numvar)),&amp;amp;i,%str( ));&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let srtvar1 = sqrt_&amp;amp;varName.;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%put &amp;amp;varName. &amp;amp;srtvar1.;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unless ou are using validvarname=ANY option.&amp;nbsp; Then you need to use name literals to allow the name to include special characters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let varName =%QSCAN(%sysfunc(compbl(&amp;amp;numvar)),&amp;amp;i,%str( ));&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%let srtvar1 = "sqrt_&amp;amp;varName."N;&lt;/P&gt;&lt;P style="font-size: 13.3333330154419px; font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; background-color: #ffffff;"&gt;%put &amp;amp;varName. &amp;amp;srtvar1.;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 29 Jun 2015 22:12:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216274#M39861</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2015-06-29T22:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Macro variable not resolving correctly</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216275#M39862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;this comment is a side note&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;this code can be simplified&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;call symput ("library", put(upcase(substr("&amp;amp;input",1,index("&amp;amp;input",'.')-1)), $8.));&lt;/P&gt;&lt;P&gt;call symput ("datset", put(upcase(substr("&amp;amp;input",index("&amp;amp;input",'.')+1,length("&amp;amp;input"))), $32.));&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;to this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;%* deconstruct data into SAS naming conventions;&lt;/P&gt;&lt;P&gt;%let data = %lowcase(&amp;amp;data);&lt;/P&gt;&lt;P&gt;%if&amp;nbsp;&amp;nbsp; %index(&amp;amp;data,.) %then %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %*is.a two-level name libref.data_name;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let libname = %scan(&amp;amp;data,1,.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let memname = %scan(&amp;amp;data,2,.);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;P&gt;%else %do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %*is.a one-level-name;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let libname = work;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %let memname = &amp;amp;data;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %end;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 30 Jun 2015 11:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-variable-not-resolving-correctly/m-p/216275#M39862</guid>
      <dc:creator>Ron_MacroMaven</dc:creator>
      <dc:date>2015-06-30T11:10:33Z</dc:date>
    </item>
  </channel>
</rss>

