<?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: Cannot resolve the macro variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727931#M226483</link>
    <description>&lt;P&gt;Forget about macro code or macro variables.&amp;nbsp; Figure out what SAS code you need.&amp;nbsp; There are a lot of ways to check the type of a variable.&amp;nbsp; There is the VTYPE() function for example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if 0 then set sashelp.cars ;
  call symputx('type',vtype(make));
run;
%put &amp;amp;=type ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use PROC CONTENTS to get all of the variables and check the TYPE variable in that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=sashelp.cars noprint out=contents; run;
proc print data=contents;
 where upcase(name)='MAKE';
 var name type;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sat, 20 Mar 2021 17:49:28 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-03-20T17:49:28Z</dc:date>
    <item>
      <title>Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727920#M226474</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options symbolgen;
%macro mac01(data=prac.mac01);
data _NULL_;
set &amp;amp;data(keep=Make);
%local first_make;
%IF _N_ = 1 %THEN %DO;
&amp;amp;first_make = Make;
call symput("First", &amp;amp;first_make);
%END;
%put &amp;amp;First;
run;

proc print data=&amp;amp;data(firstobs=1 obs=5 keep=Make) noobs;
run;
%mend mac01;

%scoreit(program=mac01)
options nosymbolgen;&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; 139        options symbolgen;
 140        %macro mac01(data=prac.mac01);
 141        data _NULL_;
 142        set &amp;amp;data(keep=Make);
 143        %local first_make;
 144        %IF _N_ = 1 %THEN %DO;
 145        &amp;amp;first_make = Make
 146        call symput("First", &amp;amp;first_make);
 147        %END;
 148        %put &amp;amp;First;
 149        run;
 150        
 151        proc print data=&amp;amp;data(firstobs=1 obs=5 keep=Make) noobs;
 152        run;
 153        %mend mac01;
 154        
 155        %scoreit(program=mac01)
 SYMBOLGEN:  Macro variable PROGRAM resolves to mac01
 SYMBOLGEN:  Macro variable DATA resolves to prac.mac01
 WARNING: Apparent symbolic reference FIRST not resolved.
 &amp;amp;First
 
 NOTE: There were 428 observations read from the data set PRAC.MAC01.
 NOTE: DATA statement used (Total process time):
       real time           0.00 seconds
       cpu time            0.00 seconds
       
 
 SYMBOLGEN:  Macro variable DATA resolves to prac.mac01
 
 NOTE: There were 5 observations read from the data set PRAC.MAC01.
 NOTE: PROCEDURE PRINT used (Total process time):
       real time           0.05 seconds
       cpu time            0.06 seconds
       
 
 156        options nosymbolgen;
 157        
 158        
 159        OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
 171        &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I cannot resolve the First macro variable, can anyone help me with that? The data is from sashelp.cars and the task is to write a macro to extract the first make value which is character.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 17:35:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727920#M226474</guid>
      <dc:creator>kc001</dc:creator>
      <dc:date>2021-03-20T17:35:08Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727921#M226475</link>
      <description>&lt;P&gt;Hello&lt;BR /&gt;I have made changes to the code as follows:-&lt;BR /&gt;&lt;BR /&gt;%macro mac01(data=prac.mac01);&lt;BR /&gt;data _NULL_;&lt;BR /&gt;set &amp;amp;data(keep=Make);&lt;BR /&gt;%local first_make;&lt;BR /&gt;%IF _N_ = 1 %THEN %DO;&lt;BR /&gt;%let first_make = Make&lt;BR /&gt;call symput("First", &amp;amp;first_make);&lt;BR /&gt;%END;&lt;BR /&gt;run;&lt;BR /&gt;%put &amp;amp;First;&lt;BR /&gt;proc print data=&amp;amp;data(firstobs=1 obs=5 keep=Make) noobs;&lt;BR /&gt;run;&lt;BR /&gt;%mend mac01;&lt;/P&gt;
&lt;P&gt;Have a look at this article&lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/243-29.pdf" target="_blank" rel="noopener"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi29/243-29.pdf&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and this&lt;/P&gt;
&lt;P&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings17/1516-2017.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings17/1516-2017.pdf&lt;/A&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 17:10:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727921#M226475</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-03-20T17:10:54Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727924#M226477</link>
      <description>&lt;P&gt;The question does not make much sense.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;The data is from sashelp.cars and the task is to write a macro to extract the first make value which is character.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;What does "make value which is character" mean?&amp;nbsp; The variable MAKE in SASHELP.CARS is a character variable. So all of the values are character by definition.&amp;nbsp; Do you mean look for character strings that cannot be converted into a number?&amp;nbsp; None of the values of MAKE in SASHELP.CARS can be converted into a number.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 17:28:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727924#M226477</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-20T17:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727925#M226478</link>
      <description>The code still does not work. Does the code work on you side? Thanks</description>
      <pubDate>Sat, 20 Mar 2021 17:30:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727925#M226478</guid>
      <dc:creator>kc001</dc:creator>
      <dc:date>2021-03-20T17:30:14Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727926#M226479</link>
      <description>I just want to clarify that the variable type of Make is character, there is no any conversion.</description>
      <pubDate>Sat, 20 Mar 2021 17:31:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727926#M226479</guid>
      <dc:creator>kc001</dc:creator>
      <dc:date>2021-03-20T17:31:31Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727927#M226480</link>
      <description>&lt;P&gt;To the macro language, everything is text. So&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%IF _N_ = 1 %THEN %DO;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;compares the text "_N_" with the text "1", which are obviously not equal, so the code between the %DO and %END is not created.&lt;/P&gt;
&lt;P&gt;I suggest you use data step language there.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 17:39:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727927#M226480</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-20T17:39:57Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727930#M226482</link>
      <description>&lt;P&gt;Your data step should be this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
set &amp;amp;data (keep=make);
call symput("first",make);
stop;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It will execute the CALL SYMPUT once and immediately terminate, so you avoid reading the whole dataset for nothing.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 17:45:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727930#M226482</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-20T17:45:17Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727931#M226483</link>
      <description>&lt;P&gt;Forget about macro code or macro variables.&amp;nbsp; Figure out what SAS code you need.&amp;nbsp; There are a lot of ways to check the type of a variable.&amp;nbsp; There is the VTYPE() function for example.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  if 0 then set sashelp.cars ;
  call symputx('type',vtype(make));
run;
%put &amp;amp;=type ;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You could use PROC CONTENTS to get all of the variables and check the TYPE variable in that.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=sashelp.cars noprint out=contents; run;
proc print data=contents;
 where upcase(name)='MAKE';
 var name type;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 20 Mar 2021 17:49:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727931#M226483</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-03-20T17:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727932#M226484</link>
      <description>&lt;P&gt;Here's the data step language&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&amp;nbsp;is talking about.&lt;/P&gt;
&lt;P&gt;No idea why you make the detour via &amp;amp;first_make so I skipped that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suggest you also make use of the mprint option.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;options mprint symbolgen;
%macro mac01(data=);
%GLOBAL First;
data _NULL_;
 set &amp;amp;data(keep=Make);
 if _N_=1 then 
  call symput("First", strip(Make));
run;
%mend mac01;
%mac01(data=sashelp.cars)
%PUT &amp;amp;=First;
/* end of program */
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can drop the "if _N_=1 then" (part of the programming statement where the macro var First is created)&lt;/P&gt;
&lt;P&gt;if you only read in the first observation&lt;/P&gt;
&lt;P&gt;set &amp;amp;data(keep=Make obs=1);&lt;/P&gt;
&lt;P&gt;The latter solution is also much faster when the input dataset is BIG!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I hope this is what you are looking for because I'm also distracted by your "first MAKE value which is character".&lt;/P&gt;
&lt;P&gt;Maybe you want to use the&amp;nbsp;ANYALPHA Function or the&amp;nbsp;NOTALPHA function??&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&lt;/P&gt;
&lt;P&gt;Koen&lt;/P&gt;</description>
      <pubDate>Sat, 20 Mar 2021 17:50:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727932#M226484</guid>
      <dc:creator>sbxkoenk</dc:creator>
      <dc:date>2021-03-20T17:50:30Z</dc:date>
    </item>
    <item>
      <title>Re: Cannot resolve the macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727958#M226499</link>
      <description>&lt;P&gt;I agree with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/60547"&gt;@sbxkoenk&lt;/a&gt;&amp;nbsp;.&lt;BR /&gt;It is better to drop if_N_=1 and use&amp;nbsp;&lt;SPAN&gt;set &amp;amp;data(keep=Make obs=1);&lt;/SPAN&gt;&lt;BR /&gt;This will only read only one observation and the program will execute faster&lt;/P&gt;</description>
      <pubDate>Sun, 21 Mar 2021 00:19:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Cannot-resolve-the-macro-variable/m-p/727958#M226499</guid>
      <dc:creator>Sajid01</dc:creator>
      <dc:date>2021-03-21T00:19:49Z</dc:date>
    </item>
  </channel>
</rss>

