<?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 with SYMPUTX Warning: Apparent symbolic reference not resolved in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516435#M139476</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216525"&gt;@publicSynechism&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Tom. This is excellent, but I need to tweak it. It stops prematurely and gives null values for the remaining selected variables if I don't use all the variables in the dataset&amp;nbsp;for &amp;amp;varlist.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Post the SAS log. Make sure to use the Insert Code icon so that the forum editor doesn't corrupt the text.&lt;/P&gt;
&lt;P&gt;Even better would be to post a small sample dataset (in the form or a data step) that everyone on the forum can use to recreate your issue.&lt;/P&gt;</description>
    <pubDate>Tue, 27 Nov 2018 17:58:03 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2018-11-27T17:58:03Z</dc:date>
    <item>
      <title>Macro with SYMPUTX Warning: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516333#M139445</link>
      <description>&lt;P&gt;I am attempting to make a macro function that creates macro variables holding the 99th percentile value of a variable. Here is a working example of the logic.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
input var1 var2;
datalines;
1 2
2 4
3 6
4 8
5 10
6 12
7 14
8 16
9 18
;
run;


proc means data=test p99;
var var1 var2;
output out=sumt p99= / autoname;
run;

data sumt;
set sumt;
drop _TYPE_ _FREQ_;
run;

data _null_;
	set sumt;
	call symputx("var1_p99", var1_p99);
	call symputx('var2_p99', var2_p99);
run;
%put &amp;amp;var1_p99;
%put &amp;amp;var2_p99;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;OUTPUT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;167  data _null_;
168      set sumt;
169      call symputx("var1_p99", var1_p99);
170      call symputx('var2_p99', var2_p99);
171  run;

NOTE: There were 1 observations read from the data set WORK.SUMT.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds


172  %put &amp;amp;var1_p99;
9
173  %put &amp;amp;var2_p99;
18&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is when I try to write the macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro p99(dsn);
	%let dsid=%sysfunc(open(&amp;amp;dsn));
	%let n=%sysfunc(attrn(&amp;amp;dsid,nvars));
	data _null_;
		set &amp;amp;dsn;
		%do i=1 %to &amp;amp;n;
			%let var=%sysfunc(varname(&amp;amp;dsid,&amp;amp;i));
			call symputx("&amp;amp;var",&amp;amp;var);
		%end;
	run;
	%do i=1 %to &amp;amp;n;
		%let var=%sysfunc(varname(&amp;amp;dsid,&amp;amp;i));
		%put &amp;amp;&amp;amp;var;
	%end;
	%let rc=%sysfunc(close(&amp;amp;dsid));
%mend p99;

%p99(sumt);

%put &amp;amp;var1_p99;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;OUTPUT&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;146  %macro p99(dsn);
147      %let dsid=%sysfunc(open(&amp;amp;dsn));
148      %let n=%sysfunc(attrn(&amp;amp;dsid,nvars));
149      data _null_;
150          set &amp;amp;dsn;
151          %do i=1 %to &amp;amp;n;
152              %let var=%sysfunc(varname(&amp;amp;dsid,&amp;amp;i));
153              call symputx("&amp;amp;var",&amp;amp;var);
154          %end;
155      run;
156      %do i=1 %to &amp;amp;n;
157          %let var=%sysfunc(varname(&amp;amp;dsid,&amp;amp;i));
158          %put &amp;amp;&amp;amp;var;
159      %end;
160      %let rc=%sysfunc(close(&amp;amp;dsid));
161  %mend p99;
162
163  %p99(sumt);

NOTE: There were 1 observations read from the data set WORK.SUMT.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds


var1_P99
var2_P99
WARNING: Apparent symbolic reference VAR1_P99 not resolved.&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I'd like it if someone could explain why the macro function&amp;nbsp;won't write the values with SYMPUTX and then point out the correction.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 15:00:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516333#M139445</guid>
      <dc:creator>publicSynechism</dc:creator>
      <dc:date>2018-11-27T15:00:27Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with SYMPUTX Warning: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516337#M139447</link>
      <description>&lt;P&gt;First, why do you want a macro to do what you can already do without it?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 15:05:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516337#M139447</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2018-11-27T15:05:52Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with SYMPUTX Warning: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516342#M139451</link>
      <description>&lt;P&gt;If I understand the question you want to take this code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	set sumt;
	call symputx("var1_p99", var1_p99);
	call symputx('var2_p99', var2_p99);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And turn it into a macro where the name of the input dataset is passed as a parameter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro p99(dsn);
data _null_;
	set &amp;amp;dsn;
	call symputx("var1_p99", var1_p99);
	call symputx('var2_p99', var2_p99);
run;
%mend p99;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Since the CALL SYMPUTX() statements are now running in macro by default the macro variable VAR1_P99 will be local to the macro and so disappear. You could just use the third argument to CALL SYMPUTX() to force them to be made as global.&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;call symputx('var2_p99', var2_p99,'g');&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or you could make the macro a little more dynamic and only make them global if they do not already exist.&amp;nbsp; Then you could call this macro from inside another macro that has already defined those macro variables in its local macro space.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro p99(dsn);
%if not %symexist(var1_p99) %then %global var1_p99;
%if not %symexist(var2_p99) %then %global var2_p99;
data _null_;
	set &amp;amp;dsn;
	call symputx("var1_p99", var1_p99);
	call symputx('var2_p99', var2_p99);
run;
%mend p99;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Nov 2018 15:19:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516342#M139451</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-27T15:19:54Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with SYMPUTX Warning: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516343#M139452</link>
      <description>&lt;P&gt;I would guess your problem lies here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token macroname"&gt;%let&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;var&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token macrostatement"&gt;%sysfunc&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;varname&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;dsid&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;amp;&lt;/SPAN&gt;i&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You are interested in numeric variables only.&amp;nbsp; But VARNAME (and &amp;amp;i) applies to all variables, not just the numeric ones.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be easier to begin by extracting one long macro variable holding the names of all numeric variables in the data set.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 15:16:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516343#M139452</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-11-27T15:16:20Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with SYMPUTX Warning: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516350#M139457</link>
      <description>&lt;P&gt;Why do you need a macro?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Before you start writing macro code first get the SAS code set.&lt;/P&gt;
&lt;P&gt;If you want to generate every variable in a dataset into macro variable there is no need for macro code.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means data=test p99;
  var var1 var2;
  output out=sumt(drop=_type_ _freq_) p99= / autoname;
run;

data _null_;
  set sumt;
  array _n _numeric_;
  do i=1 to dim(_n);
    call symputx(vname(_n(i)),n(i));
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 15:36:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516350#M139457</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-27T15:36:16Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with SYMPUTX Warning: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516355#M139459</link>
      <description>&lt;P&gt;I don't know SAS well, so after finding percentiles for a certain variable, I would type in the value by hand to subset the data. And I was doing this every time I updated the dataset. I wanted code that allows me to call a macro holding the percentile value regardless of the data I'm using.&lt;/P&gt;&lt;P&gt;I'm not sure I understand you're second suggestion. The log returns the symbolic reference not resolved warning when I call the macro associated with a particular variable.&lt;/P&gt;&lt;P&gt;Thanks for you help.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 15:51:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516355#M139459</guid>
      <dc:creator>publicSynechism</dc:creator>
      <dc:date>2018-11-27T15:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with SYMPUTX Warning: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516360#M139460</link>
      <description>&lt;P&gt;If the goal is to use the value of the variable in calculations then you will get better precision by leaving it the data and not using either the manual copy/paste or the macro version of that.&lt;/P&gt;
&lt;P&gt;For example here is a little program to calculate the 99th percentile for a set of variables and then use those values to flag observations where the value is greater than that 99th percentile.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let indsn=have;
%let varlist=var1 var2;
%let outdsn=want;

proc summary data=&amp;amp;indsn ;
  var  &amp;amp;varlist ;
  output out=percentiles(drop=_type_ _freq_)  p99= /autoname ;
run;

data &amp;amp;outdsn ;
  set &amp;amp;indsn ;
  if _n_ =1 then set precentiles;
  array x &amp;amp;varlist;
  array p %sysfunc(tranwrd(&amp;amp;varlist%str( ),%str( ),%str(_p99 )));
  array f %sysfunc(tranwrd(&amp;amp;varlist%str( ),%str( ),%str(_flag )));

  do i=1 to dim(x);
     f(i) = ( x(i) &amp;gt; p(i) );
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:00:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516360#M139460</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-27T16:00:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with SYMPUTX Warning: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516377#M139462</link>
      <description>&lt;P&gt;Thanks Tom. This is excellent, but I need to tweak it. It stops prematurely and gives null values for the remaining selected variables if I don't use all the variables in the dataset&amp;nbsp;for &amp;amp;varlist.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 16:22:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516377#M139462</guid>
      <dc:creator>publicSynechism</dc:creator>
      <dc:date>2018-11-27T16:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: Macro with SYMPUTX Warning: Apparent symbolic reference not resolved</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516435#M139476</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216525"&gt;@publicSynechism&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Tom. This is excellent, but I need to tweak it. It stops prematurely and gives null values for the remaining selected variables if I don't use all the variables in the dataset&amp;nbsp;for &amp;amp;varlist.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Post the SAS log. Make sure to use the Insert Code icon so that the forum editor doesn't corrupt the text.&lt;/P&gt;
&lt;P&gt;Even better would be to post a small sample dataset (in the form or a data step) that everyone on the forum can use to recreate your issue.&lt;/P&gt;</description>
      <pubDate>Tue, 27 Nov 2018 17:58:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-with-SYMPUTX-Warning-Apparent-symbolic-reference-not/m-p/516435#M139476</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2018-11-27T17:58:03Z</dc:date>
    </item>
  </channel>
</rss>

