<?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 error issue in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/macro-error-issue/m-p/715469#M220986</link>
    <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/113010" target="_blank"&gt;me55&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;dsid is a number, you cannot have data set name as a number.&lt;/P&gt;
&lt;P&gt;Instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;dsid;
   set &amp;amp;dsid;
   &amp;amp;var='UNK';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you probably should have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;ds;
   set &amp;amp;ds;
   &amp;amp;var='UNK';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
    <pubDate>Fri, 29 Jan 2021 21:47:15 GMT</pubDate>
    <dc:creator>LeonidBatkhan</dc:creator>
    <dc:date>2021-01-29T21:47:15Z</dc:date>
    <item>
      <title>macro error issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-error-issue/m-p/715467#M220984</link>
      <description>&lt;P&gt;okay, so i built this macro a while ago.&amp;nbsp; it was in a different thread in this forum.&amp;nbsp; i used it in the past and it worked however i am getting weird, kind of unidentified errors...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro VarExist(ds,var);
%local rc dsid result resx;
%let dsid = %sysfunc(open(&amp;amp;ds));
%let resx = %sysfunc(varnum(&amp;amp;dsid,&amp;amp;var));
%let rc = %sysfunc(close(&amp;amp;dsid));

%if &amp;amp;resx &amp;gt; 0 %then %do;
%let result = 1;
%put NOTE: Var &amp;amp;var exists in &amp;amp;ds;

%end;

%else %do;
%let result = 0;
%put NOTE: Var &amp;amp;var not exists in &amp;amp;ds;

data &amp;amp;dsid;
&amp;amp;var='UNK';
set &amp;amp;dsid;
run;

%end;
%mend VarExist;

%VarExist(TABLE_01,FIELD_01);&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;however, like i said, when i run this i get this error...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;93         
94         
98         
99         %macro VarExist(ds,var);
101        %local rc dsid result resx;
102        %let dsid = %sysfunc(open(&amp;amp;ds));
103        %let resx = %sysfunc(varnum(&amp;amp;dsid,&amp;amp;var));
104        %let rc = %sysfunc(close(&amp;amp;dsid));
105        
106        %if &amp;amp;resx &amp;gt; 0 %then %do;
107        %let result = 1;
108        %put NOTE: Var &amp;amp;var exists in &amp;amp;ds;
109        
110        %end;
111        
112        %else %do;
113        %let result = 0;
114        %put NOTE: Var &amp;amp;var not exists in &amp;amp;ds;
115        
116        data &amp;amp;dsid;
117        set &amp;amp;dsid;
118        &amp;amp;var='UNK';
119        run;
120        
121        %end;
122        %mend VarExist;
123        
124        %VarExist(TABLE_01,FIELD_01);
MLOGIC(VAREXIST):  Beginning execution.
MLOGIC(VAREXIST):  Parameter DS has value TABLE_01
MLOGIC(VAREXIST):  Parameter VAR has value FIELD_01
MLOGIC(VAREXIST):  %LOCAL  RC DSID RESULT RESX
MLOGIC(VAREXIST):  %LET (variable name is DSID)
SYMBOLGEN:  Macro variable DS resolves to TABLE_01
MLOGIC(VAREXIST):  %LET (variable name is RESX)
SYMBOLGEN:  Macro variable DSID resolves to 1
SYMBOLGEN:  Macro variable VAR resolves to FIELD_01
MLOGIC(VAREXIST):  %LET (variable name is RC)
SYMBOLGEN:  Macro variable DSID resolves to 1
SYMBOLGEN:  Macro variable RESX resolves to 0
MLOGIC(VAREXIST):  %IF condition &amp;amp;resx &amp;gt; 0 is FALSE
MLOGIC(VAREXIST):  %LET (variable name is RESULT)
MLOGIC(VAREXIST):  %PUT NOTE: Var &amp;amp;var not exists in &amp;amp;ds
SYMBOLGEN:  Macro variable VAR resolves to FIELD_01
SYMBOLGEN:  Macro variable DS resolves to TABLE_01
NOTE: Var FIELD_01 not exists in TABLE_01
SYMBOLGEN:  Macro variable DSID resolves to 1
NOTE: Line generated by the macro variable "DSID".
5                                                          The SAS System                       Friday, January 29, 2021 03:01:00 PM

124         1
            _
            22
            200
MPRINT(VAREXIST):   data 1;
SYMBOLGEN:  Macro variable DSID resolves to 1
ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, /, ;, _DATA_, _LAST_, _NULL_.  

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: Line generated by the macro variable "DSID".
124         1
            _
            22
            200
MPRINT(VAREXIST):   set 1;
SYMBOLGEN:  Macro variable VAR resolves to TBL_SRC
MPRINT(VAREXIST):   FIELD_01='UNK';
MPRINT(VAREXIST):   run;

ERROR 22-322: Syntax error, expecting one of the following: a name, a quoted string, ;, CUROBS, END, INDSNAME, KEY, KEYRESET, KEYS, 
              NOBS, OPEN, POINT, _DATA_, _LAST_, _NULL_.  

ERROR 200-322: The symbol is not recognized and will be ignored.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.DATA1 may be incomplete.  When this step was stopped there were 0 observations and 19 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
      

MLOGIC(VAREXIST):  Ending execution.
&lt;BR /&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;also, should i insert a line to close the table or does it just do that because i have the rc line in there?&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-error-issue/m-p/715467#M220984</guid>
      <dc:creator>me55</dc:creator>
      <dc:date>2021-01-29T21:42:03Z</dc:date>
    </item>
    <item>
      <title>Re: macro error issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-error-issue/m-p/715468#M220985</link>
      <description>&lt;P&gt;Here you should use the dataset name, not the handle returned by the OPEN function:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;dsid;
set &amp;amp;dsid;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;should be&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;ds;
set &amp;amp;ds;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:46:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-error-issue/m-p/715468#M220985</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-01-29T21:46:50Z</dc:date>
    </item>
    <item>
      <title>Re: macro error issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-error-issue/m-p/715469#M220986</link>
      <description>&lt;P&gt;Hi &lt;A class="trigger-hovercard" style="color: #007dc3;" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/113010" target="_blank"&gt;me55&lt;/A&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;amp;dsid is a number, you cannot have data set name as a number.&lt;/P&gt;
&lt;P&gt;Instead of&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;dsid;
   set &amp;amp;dsid;
   &amp;amp;var='UNK';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;you probably should have&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data &amp;amp;ds;
   set &amp;amp;ds;
   &amp;amp;var='UNK';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:47:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-error-issue/m-p/715469#M220986</guid>
      <dc:creator>LeonidBatkhan</dc:creator>
      <dc:date>2021-01-29T21:47:15Z</dc:date>
    </item>
    <item>
      <title>Re: macro error issue</title>
      <link>https://communities.sas.com/t5/SAS-Programming/macro-error-issue/m-p/715470#M220987</link>
      <description>&lt;P&gt;Remember that the OPEN function&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;DIV class="xis-refDictEntry"&gt;
&lt;DIV class="xis-details"&gt;
&lt;DIV id="p1h2a020z5xzman15rla4un176bv" class="xis-topicContent"&gt;
&lt;DIV id="p1l2qqtznbiiebn1pblckm2orvur" class="xis-paragraph"&gt;The &lt;FONT style="background-color: #fcdec0;"&gt;OPEN&lt;/FONT&gt; function opens a SAS data set, DATA step, or a SAS SQL view and returns a&lt;STRONG&gt;&lt;FONT color="#FF00FF"&gt; unique numeric data set identifier&lt;/FONT&gt;&lt;/STRONG&gt;, which is used in most other data set access functions. &lt;FONT style="background-color: #fcdec0;"&gt;OPEN&lt;/FONT&gt; returns 0 if the data set could not be opened.&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data set names and variable names cannot be all digits.&lt;/P&gt;
&lt;P&gt;So&lt;/P&gt;
&lt;P&gt;data &amp;amp;dsid;&lt;/P&gt;
&lt;P&gt;is not legal when creating the value for &amp;amp;dsid with the Open function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Jan 2021 21:52:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/macro-error-issue/m-p/715470#M220987</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-01-29T21:52:16Z</dc:date>
    </item>
  </channel>
</rss>

