<?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 troubleshooting - using include, eval, and put with a macro in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744487#M233246</link>
    <description>&lt;P&gt;Lets start with something simple:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have this line in your code:&lt;/P&gt;
&lt;P&gt;%let counterN = $eval(counter);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro function would be %eval, not $eval.&lt;/P&gt;
&lt;P&gt;Second, what is "counter"? The macro language does not see values of data set variables.&lt;/P&gt;
&lt;P&gt;So even the "proper" call would yield:&lt;/P&gt;
&lt;PRE&gt;671  %let counterN = %eval(counter);
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: counter
&lt;/PRE&gt;
&lt;P&gt;because the string "counter" does not contain anything that can resolve to a numeric value.&lt;/P&gt;
&lt;P&gt;These are valid&lt;/P&gt;
&lt;PRE&gt;%let counterN = %eval(1 + 2);
%put Countern is: &amp;amp;countern;

%let counterN = %eval(a=b);
%put Countern is: &amp;amp;countern;&lt;/PRE&gt;
&lt;P&gt;The equality comparison reports if the character a is the same as the character b and SAS returns 0 for false. But that is not looking at any variable value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 28 May 2021 17:59:25 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-05-28T17:59:25Z</dc:date>
    <item>
      <title>Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744478#M233237</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am currently trying to troubleshoot a macro followed by a datastep. The purpose of the program is to conduct a data quality check by identifying observations that take invalid values, which are determined by a separate variable format program that is called on using %include. The program is not designed to catch errors in the data itself, but is intended to catch errors in the variable formats -- for example, if we coded a variable as 1="yes" and 2="no" but forgot to set a value label for 3=. The code's original author intended to structure it so that the macro was applied to one variable "section" at a time, looping through all of the variable "sections" so that they could be checked separately. Here is the current version of the program:&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%macro checkvalid(sectionname, sectionformat);&lt;/P&gt;&lt;P&gt;format val_var $50. list flist $9000.;&lt;BR /&gt;list = "&amp;amp;&amp;amp;&amp;amp;sectionname.";&lt;BR /&gt;flist = "&amp;amp;&amp;amp;&amp;amp;sectionformat.";&lt;BR /&gt;counter= countw("&amp;amp;&amp;amp;&amp;amp;sectionname.");&lt;BR /&gt;%let counterN = $eval(counter);&lt;BR /&gt;put counter = "macro var = &amp;amp;counterN.";&lt;BR /&gt;put flist = ;&lt;BR /&gt;&lt;BR /&gt;%do i = 1 %to &amp;amp;counterN;&lt;BR /&gt;%let var = %scan(list,&amp;amp;i,' ');&lt;BR /&gt;%let fmt = %scan(flist,&amp;amp;i,' ');&lt;BR /&gt;put "var= " &amp;amp;var.;&lt;BR /&gt;put "fmt= " &amp;amp;fmt.;&lt;BR /&gt;val_var = put(&amp;amp;var., &amp;amp;fmt.);&lt;BR /&gt;put val_var=;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;*** apply formats that have 'Invalid' for all non valid/non missing values ***;&lt;BR /&gt;data want_obs_invalid;&lt;BR /&gt;set have;&lt;/P&gt;&lt;P&gt;%include "filepath\variable_formats_code.sas";&lt;/P&gt;&lt;P&gt;%let sectionname = &amp;amp;sectcmpl. ;&lt;BR /&gt;%let sectionformat = &amp;amp;sectfmt. ;&lt;BR /&gt;format val_var $50. list flist $9000.;&lt;BR /&gt;list = "&amp;amp;&amp;amp;&amp;amp;sectionname.";&lt;BR /&gt;flist = "&amp;amp;&amp;amp;&amp;amp;sectionformat.";&lt;BR /&gt;%let counter= countw("&amp;amp;&amp;amp;&amp;amp;sectionname.");&lt;BR /&gt;%let counterN = $eval(counter);&lt;BR /&gt;put counter = "macro var = &amp;amp;counterN.";&lt;BR /&gt;put flist = ;&lt;BR /&gt;/* Loop through the variables and check for invalid values */&lt;BR /&gt;%checkvalid(sectionname, sectionformat);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;************;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The errors I am getting are "ERROR: Required operator not found in expression: &amp;amp;counterN&lt;BR /&gt;ERROR: The %TO value of the %DO I loop is invalid." I would appreciate any suggestions on how to resolve the issue (as well as any suggestions for a more efficient way of going about this!). Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 17:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744478#M233237</guid>
      <dc:creator>MHines</dc:creator>
      <dc:date>2021-05-28T17:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744481#M233240</link>
      <description>&lt;P&gt;Can you add the following options before your macro and then show the full log?&lt;BR /&gt;&lt;BR /&gt;options mprint symbolgen;&lt;BR /&gt;&lt;BR /&gt;That will provide more information making it easier to debug this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-SPOILER&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/362272"&gt;@MHines&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I am currently trying to troubleshoot a macro followed by a datastep. The purpose of the program is to conduct a data quality check by identifying observations that take invalid values, which are determined by a separate variable format program that is called on using %include. The program is not designed to catch errors in the data itself, but is intended to catch errors in the variable formats -- for example, if we coded a variable as 1="yes" and 2="no" but forgot to set a value label for 3=. The code's original author intended to structure it so that the macro was applied to one variable "section" at a time, looping through all of the variable "sections" so that they could be checked separately. Here is the current version of the program:&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;%macro checkvalid(sectionname, sectionformat);&lt;/P&gt;
&lt;P&gt;format val_var $50. list flist $9000.;&lt;BR /&gt;list = "&amp;amp;&amp;amp;&amp;amp;sectionname.";&lt;BR /&gt;flist = "&amp;amp;&amp;amp;&amp;amp;sectionformat.";&lt;BR /&gt;counter= countw("&amp;amp;&amp;amp;&amp;amp;sectionname.");&lt;BR /&gt;%let counterN = $eval(counter);&lt;BR /&gt;put counter = "macro var = &amp;amp;counterN.";&lt;BR /&gt;put flist = ;&lt;BR /&gt;&lt;BR /&gt;%do i = 1 %to &amp;amp;counterN;&lt;BR /&gt;%let var = %scan(list,&amp;amp;i,' ');&lt;BR /&gt;%let fmt = %scan(flist,&amp;amp;i,' ');&lt;BR /&gt;put "var= " &amp;amp;var.;&lt;BR /&gt;put "fmt= " &amp;amp;fmt.;&lt;BR /&gt;val_var = put(&amp;amp;var., &amp;amp;fmt.);&lt;BR /&gt;put val_var=;&lt;BR /&gt;%end;&lt;BR /&gt;%mend;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;*** apply formats that have 'Invalid' for all non valid/non missing values ***;&lt;BR /&gt;data want_obs_invalid;&lt;BR /&gt;set have;&lt;/P&gt;
&lt;P&gt;%include "filepath\variable_formats_code.sas";&lt;/P&gt;
&lt;P&gt;%let sectionname = &amp;amp;sectcmpl. ;&lt;BR /&gt;%let sectionformat = &amp;amp;sectfmt. ;&lt;BR /&gt;format val_var $50. list flist $9000.;&lt;BR /&gt;list = "&amp;amp;&amp;amp;&amp;amp;sectionname.";&lt;BR /&gt;flist = "&amp;amp;&amp;amp;&amp;amp;sectionformat.";&lt;BR /&gt;%let counter= countw("&amp;amp;&amp;amp;&amp;amp;sectionname.");&lt;BR /&gt;%let counterN = $eval(counter);&lt;BR /&gt;put counter = "macro var = &amp;amp;counterN.";&lt;BR /&gt;put flist = ;&lt;BR /&gt;/* Loop through the variables and check for invalid values */&lt;BR /&gt;%checkvalid(sectionname, sectionformat);&lt;BR /&gt;run;&lt;/P&gt;
&lt;P&gt;************;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The errors I am getting are "ERROR: Required operator not found in expression: &amp;amp;counterN&lt;BR /&gt;ERROR: The %TO value of the %DO I loop is invalid." I would appreciate any suggestions on how to resolve the issue (as well as any suggestions for a more efficient way of going about this!). Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;/LI-SPOILER&gt;</description>
      <pubDate>Fri, 28 May 2021 17:42:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744481#M233240</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-05-28T17:42:19Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744484#M233243</link>
      <description>&lt;PRE&gt;Here is the full log:&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;14672  options mprint symbolgen;
14673  %macro chkvalid(snm, sfmt);
14674
14675      format val_var $50. list flist $9000.;
14676      list = "&amp;amp;&amp;amp;&amp;amp;snm.";
14677      flist = "&amp;amp;&amp;amp;&amp;amp;sfmt.";
14678      counter= countw("&amp;amp;&amp;amp;&amp;amp;snm.");
14679      %let counterN = $eval(counter);
14680      put counter =  "macro var = &amp;amp;counterN.";
14681      put flist = ;
14682
14683      %do i = 1 %to &amp;amp;counterN;
14684          %let var = %scan(list,&amp;amp;i,' ');
14685          %let fmt = %scan(flist,&amp;amp;i,' ');
14686          put "var= " &amp;amp;var.;
14687          put "fmt= " &amp;amp;fmt.;
14688          val_var = put(&amp;amp;var., &amp;amp;fmt.);
14689          put val_var=;
14690      %end;
14691
14692  %mend;
14693  *** apply formats that have 'Invalid' for all non valid/non missing values ***;
14694  data redcap_probs /* (keep=studyid section variable_name val_var)*/;
SYMBOLGEN:  Macro variable INREDCAP resolves to inlib.GEIPR_data_20210505
14695      set &amp;amp;inredcap.(obs=10 where=(fully_enrolled=1));
14696
14697      %include "S:\Projects\Inpatient_MOA\PROGRAMS\GEIPR\DQ_Checks_Final\11_DQ_formatcode.sas";
15322
15323      %let snm = &amp;amp;sectcmpl. ;
SYMBOLGEN:  Macro variable SECTCMPL resolves to prescreening_form_complete                         control_matching_ver_complete
                    recruitment_screening_complete                         consent_form_complete
            illness_interview_complete                         case_matching_criteria_complete                         enrollment_residual_part1
                                    enrollment_residual_part2                         enrollment_interview_complete
            casecontrol_match_complete                         first_followup_schedule_complete
            enrollment_incentive_complete                         first_followup_phone_complete
            first_followup_blood_complete                         first_followup_inter_complete
            first_followup_incen_complete                         readmit_1_blood_complete                         readmit_2_blood_complete
                               readmit_3_blood_complete                         vaccine_verification_complete
            death_form_complete                         withdrawal_form_complete
15324      %let sfmt = &amp;amp;sectfmt. ;
SYMBOLGEN:  Macro variable SECTFMT resolves to SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.
15325      format val_var $50. list flist $9000.;
15326      list = "&amp;amp;&amp;amp;&amp;amp;snm.";
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable SNM resolves to prescreening_form_complete                         control_matching_ver_complete
               recruitment_screening_complete                         consent_form_complete                         illness_interview_complete
                                  case_matching_criteria_complete                         enrollment_residual_part1
            enrollment_residual_part2                         enrollment_interview_complete                         casecontrol_match_complete
                                  first_followup_schedule_complete                         enrollment_incentive_complete
            first_followup_phone_complete                         first_followup_blood_complete
            first_followup_inter_complete                         first_followup_incen_complete                         readmit_1_blood_complete
                                    readmit_2_blood_complete                         readmit_3_blood_complete
            vaccine_verification_complete                         death_form_complete                         withdrawal_form_complete
WARNING: Apparent symbolic reference PRESCREENING_FORM_COMPLETE not resolved.
15327      flist = "&amp;amp;&amp;amp;&amp;amp;sfmt.";
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable SFMT resolves to SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.
WARNING: Apparent symbolic reference SECTION_COMPLETE not resolved.
15328      %let counter= countw("&amp;amp;&amp;amp;&amp;amp;snm.");
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable SNM resolves to prescreening_form_complete                         control_matching_ver_complete
               recruitment_screening_complete                         consent_form_complete                         illness_interview_complete
                                  case_matching_criteria_complete                         enrollment_residual_part1
            enrollment_residual_part2                         enrollment_interview_complete                         casecontrol_match_complete
                                  first_followup_schedule_complete                         enrollment_incentive_complete
            first_followup_phone_complete                         first_followup_blood_complete
            first_followup_inter_complete                         first_followup_incen_complete                         readmit_1_blood_complete
                                    readmit_2_blood_complete                         readmit_3_blood_complete
            vaccine_verification_complete                         death_form_complete                         withdrawal_form_complete
WARNING: Apparent symbolic reference PRESCREENING_FORM_COMPLETE not resolved.
15329      %let counterN = $eval(counter); /*https://support.sas.com/documentation/cdl/en/mcrolref/61885/HTML/default/viewer.htm#a000208971.htm*/
15330      put counter =  "macro var = &amp;amp;counterN.";
SYMBOLGEN:  Macro variable COUNTERN resolves to $eval(counter)
15331      put flist = ;
15332  /* Loop through the variables and check for invalid values */
15333      %chkvalid(sectcmpl, sectfmt);
MPRINT(CHKVALID):   format val_var $50. list flist $9000.;
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable SNM resolves to sectcmpl
SYMBOLGEN:  Macro variable SECTCMPL resolves to prescreening_form_complete                         control_matching_ver_complete
                    recruitment_screening_complete                         consent_form_complete
            illness_interview_complete                         case_matching_criteria_complete                         enrollment_residual_part1
                                    enrollment_residual_part2                         enrollment_interview_complete
            casecontrol_match_complete                         first_followup_schedule_complete
            enrollment_incentive_complete                         first_followup_phone_complete
            first_followup_blood_complete                         first_followup_inter_complete
            first_followup_incen_complete                         readmit_1_blood_complete                         readmit_2_blood_complete
                               readmit_3_blood_complete                         vaccine_verification_complete
            death_form_complete                         withdrawal_form_complete
MPRINT(CHKVALID):   list = "prescreening_form_complete                         control_matching_ver_complete
recruitment_screening_complete                         consent_form_complete                         illness_interview_complete
       case_matching_criteria_complete                         enrollment_residual_part1                         enrollment_residual_part2
                  enrollment_interview_complete                         casecontrol_match_complete
first_followup_schedule_complete                         enrollment_incentive_complete                         first_followup_phone_complete
                    first_followup_blood_complete                         first_followup_inter_complete
first_followup_incen_complete                         readmit_1_blood_complete                         readmit_2_blood_complete
       readmit_3_blood_complete                         vaccine_verification_complete                         death_form_complete
         withdrawal_form_complete";
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable SFMT resolves to sectfmt
SYMBOLGEN:  Macro variable SECTFMT resolves to SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
            SECTION_COMPLETE.                         SECTION_COMPLETE.
MPRINT(CHKVALID):   flist = "SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
          SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
                       SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
    SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.                         SECTION_COMPLETE.
                       SECTION_COMPLETE.                         SECTION_COMPLETE.";
SYMBOLGEN:  &amp;amp;&amp;amp; resolves to &amp;amp;.
SYMBOLGEN:  Macro variable SNM resolves to sectcmpl
SYMBOLGEN:  Macro variable SECTCMPL resolves to prescreening_form_complete                         control_matching_ver_complete
                    recruitment_screening_complete                         consent_form_complete
            illness_interview_complete                         case_matching_criteria_complete                         enrollment_residual_part1
                                    enrollment_residual_part2                         enrollment_interview_complete
            casecontrol_match_complete                         first_followup_schedule_complete
            enrollment_incentive_complete                         first_followup_phone_complete
            first_followup_blood_complete                         first_followup_inter_complete
            first_followup_incen_complete                         readmit_1_blood_complete                         readmit_2_blood_complete
                               readmit_3_blood_complete                         vaccine_verification_complete
            death_form_complete                         withdrawal_form_complete
MPRINT(CHKVALID):   counter= countw("prescreening_form_complete                         control_matching_ver_complete
recruitment_screening_complete                         consent_form_complete                         illness_interview_complete
       case_matching_criteria_complete                         enrollment_residual_part1                         enrollment_residual_part2
                  enrollment_interview_complete                         casecontrol_match_complete
first_followup_schedule_complete                         enrollment_incentive_complete                         first_followup_phone_complete
                    first_followup_blood_complete                         first_followup_inter_complete
first_followup_incen_complete                         readmit_1_blood_complete                         readmit_2_blood_complete
       readmit_3_blood_complete                         vaccine_verification_complete                         death_form_complete
         withdrawal_form_complete");
SYMBOLGEN:  Macro variable COUNTERN resolves to $eval(counter)
MPRINT(CHKVALID):   put counter = "macro var = $eval(counter)";
MPRINT(CHKVALID):   put flist = ;
SYMBOLGEN:  Macro variable COUNTERN resolves to $eval(counter)
ERROR: Required operator not found in expression: &amp;amp;counterN
ERROR: The %TO value of the %DO I loop is invalid.
ERROR: The macro CHKVALID will stop executing.
15334  run;

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.REDCAP_PROBS may be incomplete.  When this step was stopped there were 0 observations and 994 variables.
WARNING: Data set WORK.REDCAP_PROBS was not replaced because this step was stopped.
NOTE: DATA statement used (Total process time):
      real time           6.04 seconds
      cpu time            3.78 seconds

&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 May 2021 17:43:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744484#M233243</guid>
      <dc:creator>MHines</dc:creator>
      <dc:date>2021-05-28T17:43:02Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744485#M233244</link>
      <description>Thank you for the suggestion -- I have added the full log as a reply to the original post.</description>
      <pubDate>Fri, 28 May 2021 17:46:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744485#M233244</guid>
      <dc:creator>MHines</dc:creator>
      <dc:date>2021-05-28T17:46:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744487#M233246</link>
      <description>&lt;P&gt;Lets start with something simple:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have this line in your code:&lt;/P&gt;
&lt;P&gt;%let counterN = $eval(counter);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro function would be %eval, not $eval.&lt;/P&gt;
&lt;P&gt;Second, what is "counter"? The macro language does not see values of data set variables.&lt;/P&gt;
&lt;P&gt;So even the "proper" call would yield:&lt;/P&gt;
&lt;PRE&gt;671  %let counterN = %eval(counter);
ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric
       operand is required. The condition was: counter
&lt;/PRE&gt;
&lt;P&gt;because the string "counter" does not contain anything that can resolve to a numeric value.&lt;/P&gt;
&lt;P&gt;These are valid&lt;/P&gt;
&lt;PRE&gt;%let counterN = %eval(1 + 2);
%put Countern is: &amp;amp;countern;

%let counterN = %eval(a=b);
%put Countern is: &amp;amp;countern;&lt;/PRE&gt;
&lt;P&gt;The equality comparison reports if the character a is the same as the character b and SAS returns 0 for false. But that is not looking at any variable value.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 17:59:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744487#M233246</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-28T17:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744494#M233247</link>
      <description>&lt;P&gt;My understanding is that "counter" is meant to identify the names of the variables within the section and counterN is meant to evaluate the values each variable takes within the section -- do you think it makes more sense to just ignore the "sections" and just look at all variables at once? Would an array with a do loop make more sense? I re-ran the code using %eval instead of $eval and, as you indicated, got the following error "ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: counter&lt;BR /&gt;ERROR: The macro CHKVALID will stop executing."&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 18:15:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744494#M233247</guid>
      <dc:creator>MHines</dc:creator>
      <dc:date>2021-05-28T18:15:30Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744503#M233249</link>
      <description>&lt;P&gt;Your basic program structure does make sense to me.&lt;/P&gt;
&lt;P&gt;What is in the %INCLUDE file?&amp;nbsp; The way you have written your program it should only include statements that would be valid in a data step.&amp;nbsp; But based on the name it looks like it might include some PROC FORMAT code.&amp;nbsp; If it does then you should run the PROC FORMAT step before starting your data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you add the / source2 option to the %INCLUDE statement you will see the lines of code in the LOG.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Macro statements run before the data step (they run before SAS even starts trying to compile the data step).&amp;nbsp; So move your %LET statements before the DATA statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The macro seems to sort of just generate statements to run in a data step.&amp;nbsp; So you might be able to call it multiple times in the same data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So perhaps your code needs to look something like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%include "filepath\variable_formats_code.sas";
%macro checkvalid(section,format);
/* generate data step code to check if variable SECTION
   has values that are valid for format FORMAT
*/
%mend ;

data want_obs_invalid;
  set have;
 %checkvalid(section1, formatA);
 %checkvalid(section2, formatB);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But you have a lot of details still to work out.&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 18:28:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744503#M233249</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-28T18:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744505#M233250</link>
      <description>&lt;P&gt;Hi Tom, you are correct -- my datastep does call on the macro repeatedly to loop through the sections; I just included it once here because I figured that the repeated use of the macro was not the source of the error.&lt;/P&gt;&lt;P&gt;The %include file is structured as:&amp;nbsp;&lt;/P&gt;&lt;P&gt;format var_1 var_1_fmt.&amp;nbsp;&lt;/P&gt;&lt;P&gt;format var_2 var_2_fmt.&lt;/P&gt;&lt;P&gt;format var_3 var_3_fmt.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, here are the first two:&lt;/P&gt;&lt;P&gt;format ps_age50 ps_age50_.;&lt;BR /&gt;format ps_admit10 ps_admit10_.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The program does call on a format library prior to the macro and %include statement, as follows:&lt;/P&gt;&lt;P&gt;libname dqfmtlib "S:\filepath\DQFormatlib";&lt;BR /&gt;options orientation=landscape fmtsearch=(dqfmtlib) ps=39 ls=145 compress=yes errors=1 nofmterr&lt;BR /&gt;symbolgen nocenter noquotelenmax /*noreplace*/;&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 18:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744505#M233250</guid>
      <dc:creator>MHines</dc:creator>
      <dc:date>2021-05-28T18:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744526#M233254</link>
      <description>&lt;P&gt;So what is the logic for telling if variable&amp;nbsp;ps_age50 has valid values for the format ps_age50_. ?&lt;/P&gt;
&lt;P&gt;Do you just want to check if the formatted value is different from the raw value?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if cats(ps_age50) ne vvalue(ps_age50) then put 'ERROR: Unformatted value ' ps_age50 =; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or does the format definition for PS_AGE50_ format include and OTHER category that displays invalid data as some fixed text, like UNKNOWN?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 'UNKNOWN' eq vvalue(ps_age50) then put 'ERROR: Unformatted value ' ps_age50 = best32.; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 28 May 2021 19:23:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744526#M233254</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-05-28T19:23:13Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744527#M233255</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/362272"&gt;@MHines&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;My understanding is that "counter" is meant to identify the names of the variables within the section and counterN is meant to evaluate the values each variable takes within the section -- do you think it makes more sense to just ignore the "sections" and just look at all variables at once? Would an array with a do loop make more sense? I re-ran the code using %eval instead of $eval and, as you indicated, got the following error "ERROR: A character operand was found in the %EVAL function or %IF condition where a numeric operand is required. The condition was: counter&lt;BR /&gt;ERROR: The macro CHKVALID will stop executing."&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The macro language is preprocessed prior to the data step actually executing so it can build the code elements that a procedure or data step might use. PREPROCESS. So the macro functions and statements do not ever see the value of any data step variable. You created a data step variable and then attempt to use %eval on that variable.&lt;/P&gt;
&lt;P&gt;This looks like what I think "checkvalid" is partially supposed to do at least as far a pullling a list of values apart and aligning two lists.&lt;/P&gt;
&lt;PRE&gt;%let list1 = a b c d;
%let list2 = 1. 2. 3. 4.;

%macro listloop( v1, v2);
   %do i=1 %to %sysfunc(countw(&amp;amp;v1.));
      %let var = %scan(&amp;amp;v1.,&amp;amp;i,' ');
      %let fmt = %scan(&amp;amp;v2.,&amp;amp;i,' ');
      %put i= &amp;amp;i. var= &amp;amp;var. fmt= &amp;amp;fmt.;
   %end;
%mend;

%listloop (&amp;amp;list1. , &amp;amp;list2.);&lt;/PRE&gt;
&lt;P&gt;I don't actually see anything "validating" values, especially not any useful way.&lt;/P&gt;
&lt;P&gt;As far as I can tell if your program "worked" you would have a log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looping through a data set with a pile of "put" statements doesn't sound very efficient.&lt;/P&gt;
&lt;P&gt;I suggest providing: a small sample data set, maybe 4 or 5 variables, and enough records to show some variable with "all" the format values and a couple without (so we have something invalid). The what you might expect.&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 19:23:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/744527#M233255</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-28T19:23:24Z</dc:date>
    </item>
    <item>
      <title>Re: Macro troubleshooting - using include, eval, and put with a macro</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/745199#M233556</link>
      <description>&lt;P&gt;Hello, thank you for the question and apologies for the delayed response! The formats do include an "other" category to catch invalid values. Our goal is to identify instances where the values fall into the "other" category. See below for an example:&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="left"&gt;
&lt;TABLE summary="Page Layout" cellspacing="0" cellpadding="0"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;
&lt;PRE class="batch"&gt;----------------------------------------------------------------------------                                                                     
|                   FORMAT NAME: CASECONTROL_ LENGTH: 12                   |                                                                     
|   MIN LENGTH:   1  MAX LENGTH:  40  DEFAULT LENGTH:  12  FUZZ: STD       |                                                                     
|--------------------------------------------------------------------------|                                                                     
|START           |END             |LABEL  (VER. 9.4     26MAY2021:10:25:26)|                                                                     
|----------------+----------------+----------------------------------------|                                                                     
|               .|               .|missing                                 |                                                                     
|               1|               1|Case                                    |                                                                     
|               2|               2|Control                                 |                                                                     
|**OTHER**       |**OTHER**       |Invalid Code                            |                                                                     
----------------------------------------------------------------------------                                                                     &lt;/PRE&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 02 Jun 2021 14:31:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-troubleshooting-using-include-eval-and-put-with-a-macro/m-p/745199#M233556</guid>
      <dc:creator>MHines</dc:creator>
      <dc:date>2021-06-02T14:31:15Z</dc:date>
    </item>
  </channel>
</rss>

