<?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: Conditional Programming with IF-THEN-DO in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549707#M152570</link>
    <description>Thank you very much, Kurt Bremser. This code also works, with a logic distinct from my original code. I wish I could accept more than one suggestion as a solution!</description>
    <pubDate>Tue, 09 Apr 2019 16:51:53 GMT</pubDate>
    <dc:creator>dbcrow</dc:creator>
    <dc:date>2019-04-09T16:51:53Z</dc:date>
    <item>
      <title>Conditional Programming with IF-THEN-DO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549452#M152458</link>
      <description>&lt;P&gt;Hi, SAS Users-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This seems so basic that I should be able to solve it, but here goes.&amp;nbsp; I want to cycle through a bunch of files and manipulate variables (recode, create, etc.) in each.&amp;nbsp; Some of the files have one prefix ("ed"), some have another ("pdd"), and the files are successive years (in this example, just 2016-2017).&amp;nbsp; The catch is that I would to apply some of the data manipulations only to the "ed" files and other data manipulations only to the "pdd" files using conditional ("IF/THEN/DO") programming. Many of these data manipulations are complicated and themselves require if-then statements.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My strategy is to start basic to see if I can create a double loop with IF/THEN/DO statements.&amp;nbsp; This is what I came up with, and it doesn't work:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	x = "pdd ed";
	max = countw(x);
	do i = 1 to max;
		call symput("max",max);
		call symput("type"||left(put(i, 1.)),scan(x,i));
	end;
run;

%put &amp;amp;max &amp;amp;type1 &amp;amp;type2;

%macro joinfile(startyr,endyr);
data _null_;
	%do j=1 %to &amp;amp;max.;
		%do i=&amp;amp;startyr. %to &amp;amp;endyr.; 

	if &amp;amp;&amp;amp;type&amp;amp;j. = "pdd" then 
		do;
			%put yes;
		end;
	else 
		do;
			%put nope; 
		end;

	%end;
%end;
run ;

%mend joinfile;
%joinfile(16,17); &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I get this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;yes
nope
yes
nope
yes
nope
yes
nope

NOTE: Variable pdd is uninitialized.
NOTE: Variable ed is uninitialized.
NOTE: DATA statement used (Total process time):
      real time           0.02 seconds
      cpu time            0.03 seconds&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The more complicated code doesn't work either, but maybe for reasons distinct from why this doesn't work:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;*Define macro variable "type" to specify ED or PDD files in loop below;
data _null_;
	x = "pdd ed";
	max = countw(x);
	do i = 1 to max;
		call symput("max",max);
		call symput("type"||left(put(i, 1.)),scan(x,i));
	end;
run;


%macro joinfile2(startyr,endyr);
%LET NUMDX=25;
%LET NUMEC=5;
	%do j=1 %to &amp;amp;max.;
		%do i=&amp;amp;startyr. %to &amp;amp;endyr.; 

/***CONDITIONAL CODE***/
DATA &amp;amp;&amp;amp;type&amp;amp;j..&amp;amp;i._2;
	SET &amp;amp;&amp;amp;type&amp;amp;j..&amp;amp;i.;
    
	IF &amp;amp;&amp;amp;type&amp;amp;j.. = "pdd" THEN 
		DO 

**********************************************************************************
      STEP 2 (A): CREATE INJURY SUBSET: FOR HOSPITAL DISCHARGE DATA 
      SKIP THIS STEP IF YOU USE EMRGENCY DEPARTMENT DATA
***********************************************************************************

** USE PRINCIPAL DIAGNOSIS FIELD (1ST LISTED) TO IDENTIFY INJURY CASES;
 

	**IDENTIFY VALID INJURY CASES IN THE PRINCIPAL DIAGNOSIS FIELD;
	IF SUBSTR(ICD10_3F1,1,1)='S' OR 'T07'&amp;lt;=ICD10_3F1&amp;lt;='T34' OR 
    	'T36'&amp;lt;=ICD10_3F1&amp;lt;='T50' OR 'T51'&amp;lt;=ICD10_3F1&amp;lt;='T65' OR
    	'T66'&amp;lt;=ICD10_3F1&amp;lt;='T77' OR ICD10_3F1='T79' THEN INJDX=1;             
	ELSE INJDX=0;

	** IDENTIFY ADVERSE EFFECTS/UNDERDOSING, AND ASSIGN THEM AS NON-INJURY;
    IF 'T36'&amp;lt;=ICD10_3F1&amp;lt;='T50' AND SUBSTR(ICD10_6F1,6,1) IN ('5','6') THEN INJDX=0;   
    IF ICD10_4F1 IN ('T369','T379','T399','T414','T427','T439','T459','T479','T499')  
	   AND  SUBSTR(ICD10_6F1,5,1) IN ('5','6') THEN INJDX=0;                          

    IF ENCT1="S" THEN INJDX=0;

	** REMOVE NON-INJURY CASES TO CREATE FINAL INJURY CASE SUBSET (EXCLUDES SEQUELAE);
	IF INJDX=0  THEN DELETE;
		END;

	ELSE
		DO;

**************************************************************************************************
      STEP 2 (B): CREATE INJURY SUBSET: FOR EMERGENCY DEPARTMENT DATA
      SKIP THIS STEP IF YOU USE HOSPITAL DISCHARGE DATA
**************************************************************************************************
** USE INJURY DIGNOSIS CODES IN THE PRINCIPAL DIAGNOSIS AND EXTERNAL CAUSE CODES (IN ALL DIAGNOSIS AND EXTERNAL CAUSE FIELDS) TO IDENTIFY INJURY CASES;
** SAS ARRAY IS TO SEARCH VALID EXTERNAL CAUSE CODES IN ALL DIAGNOSIS AND EXTERNAL CAUSE FIELDS;

    ARRAY ICD10F {&amp;amp;NUMDX} $ ICD10F1 - ICD10F&amp;amp;NUMDX;                    ** ARRAY FOR FORMATTED DIAGNOSIS FIELDS;
    ARRAY ICD10_6F {&amp;amp;NUMDX} $ ICD10_6F1 - ICD10_6F&amp;amp;NUMDX;              ** ARRAY FOR FORMATTED DIAGNOSIS FIELDS LIMITED TO 6 CHARACTERS;
    ARRAY ICD10_5F {&amp;amp;NUMDX} $ ICD10_5F1 - ICD10_5F&amp;amp;NUMDX;              ** ARRAY FOR FORMATTED DIAGNOSIS FIELDS LIMITED TO 5 CHARACTERS;
    ARRAY ICD10_4F {&amp;amp;NUMDX} $ ICD10_4F1 - ICD10_4F&amp;amp;NUMDX;              ** ARRAY FOR FORMATTED DIAGNOSIS FIELDS LIMITED TO 4 CHARACTERS;
    ARRAY ICD10_3F {&amp;amp;NUMDX} $ ICD10_3F1 - ICD10_3F&amp;amp;NUMDX;              ** ARRAY FOR FORMATTED DIAGNOSIS FIELDS LIMITED TO 3 CHARACTERS;
	ARRAY ENCT {&amp;amp;NUMDX} $ ENCT1 - ENCT&amp;amp;NUMDX;                    	   ** ARRAY FOR ENCOUNTER CHARACTER;
	ARRAY CAUSE_D {&amp;amp;NUMDX} CAUSE_D1 - CAUSE_D&amp;amp;NUMDX;				   ** ARRAY FOR VALID EXTERNAL CAUSE CODE DERIVED FROM DIAGNOSIS FIELDS;

    ARRAY ECODEF {&amp;amp;NUMEC} $ ECODEF1 - ECODEF&amp;amp;NUMEC;                      ** ARRAY FOR FORMATTED ECODE FIELDS;
    ARRAY ECODE_6F {&amp;amp;NUMEC} $ ECODE_6F1 - ECODE_6F&amp;amp;NUMEC;                ** ARRAY FOR FORMATTED EXTERNAL CAUSE FIELDS LIMITED TO 6 CHARACTERS;
    ARRAY ECODE_5F {&amp;amp;NUMEC} $ ECODE_5F1 - ECODE_5F&amp;amp;NUMEC;                ** ARRAY FOR FORMATTED EXTERNAL CAUSE FIELDS LIMITED TO 5 CHARACTERS;
    ARRAY ECODE_4F {&amp;amp;NUMEC} $ ECODE_4F1 - ECODE_4F&amp;amp;NUMEC;                ** ARRAY FOR FORMATTED EXTERNAL CAUSE FIELDS LIMITED TO 4 CHARACTERS;
    ARRAY ECODE_3F {&amp;amp;NUMEC} $ ECODE_3F1 - ECODE_3F&amp;amp;NUMEC;                ** ARRAY FOR FORMATTED EXTERNAL CAUSE FIELDS LIMITED TO 3 CHARACTERS;
    ARRAY ENCTE {&amp;amp;NUMEC} $ ENCTE1 - ENCTE&amp;amp;NUMEC;                    	   ** ARRAY FOR ENCOUNTER CHARACTER;
	ARRAY CAUSE_E {&amp;amp;NUMEC} CAUSE_E1 - CAUSE_E&amp;amp;NUMEC;					   ** ARRAY FOR VALID EXTERNAL CAUSE CODE DEDRIVED FROM EXTERNAL CAUSE FIELDS;

	**IDENTIFY INJURY CASES USING INJURY DIAGNOSIS CODES IN THE PRINCIPAL DIAGNOSIS FIELD;
	IF SUBSTR(ICD10_3F1,1,1)='S' OR 'T07'&amp;lt;=ICD10_3F1&amp;lt;='T34' OR 
    	'T36'&amp;lt;=ICD10_3F1&amp;lt;='T50' OR 'T51'&amp;lt;=ICD10_3F1&amp;lt;='T65' OR
    	'T66'&amp;lt;=ICD10_3F1&amp;lt;='T77' OR ICD10_3F1='T79' THEN INJDX=1;             
		ELSE INJDX=0;


		** IDENTIFY ADVERSE EFFECTS/UNDERDOSING, SEQUELAE IN THE PRINCIPLE DIAGNOSIS FIELD, AND ASSIGN THEM AS NON-INJURY;
    	IF 'T36'&amp;lt;=ICD10_3F1&amp;lt;='T50' AND SUBSTR(ICD10_6F1,6,1) IN ('5','6') THEN INJDX=0;   
   		IF ICD10_4F1 IN ('T369','T379','T399','T414','T427','T439','T459','T479','T499')  
		AND  SUBSTR(ICD10_6F1,5,1) IN ('5','6') THEN INJDX=0;                        

		IF ENCT1='S' THEN INJDX=0;


	** IDENTIFY VALID EXTERNAL CAUSE CODES IN ALL DIAGNOSIS FIELDS;
    DO I=1 TO &amp;amp;NUMDX;
	IF 'V00'&amp;lt;=ICD10_3F{I}&amp;lt;='V99' OR 'W00'&amp;lt;=ICD10_3F{I}&amp;lt;='X58' OR 'X71'&amp;lt;=ICD10_3F{I}&amp;lt;='X83' OR 'X92'&amp;lt;=ICD10_3F{I}&amp;lt;='Y09' 
     	OR 'Y21'&amp;lt;=ICD10_3F{I}&amp;lt;='Y33' OR 'Y35'&amp;lt;=ICD10_3F{I}&amp;lt;='Y38' OR 'T15'&amp;lt;=ICD10_3F{I}&amp;lt;='T19' OR 'T36'&amp;lt;=ICD10_3F{I}&amp;lt;='T50' 
     	OR 'T51'&amp;lt;=ICD10_3F{I}&amp;lt;='T65' OR ICD10_3F{I} IN ('T71', 'T73', 'T74','T76') 
     	OR ICD10_5F{I}='T1491' OR ICD10_4F{I} IN ('T750', 'T752', 'T753') THEN CAUSE_D{I}=1;
	 	ELSE CAUSE_D{I}=0;

		** ASSIGN ADVERSE EFFECTS/UNDERDOSING AND SEQUELAE AS NON-VALID ECODE;
		IF 'T36'&amp;lt;= ICD10_3F{I} &amp;lt;='T50' AND SUBSTR(ICD10_6F{I},6,1) IN ('5','6')  THEN  CAUSE_D{I}=0;   
        IF ICD10_4F{I} IN ('T369','T379','T399','T414','T427','T439','T459','T479','T499')  
		AND  SUBSTR(ICD10_6F{I},5,1) IN ('5','6') THEN  CAUSE_D{I}=0;     

        IF ENCT{I}='S' THEN CAUSE_D{I}=0;   	                                                                  
    END;


	** IDENTIFY VALID EXTERNAL CAUSE CODES IN ALL EXTERNAL CAUSE FIELDS;
    DO J=1 TO &amp;amp;NUMEC;
    IF 'V00'&amp;lt;=ECODE_3F{J}&amp;lt;='V99' OR 'W00'&amp;lt;=ECODE_3F{J}&amp;lt;='X58' OR 'X71'&amp;lt;=ECODE_3F{J}&amp;lt;='X83' OR 'X92'&amp;lt;=ECODE_3F{J}&amp;lt;='Y09' 
     	OR 'Y21'&amp;lt;=ECODE_3F{J}&amp;lt;='Y33' OR 'Y35'&amp;lt;=ECODE_3F{J}&amp;lt;='Y38' OR 'T15'&amp;lt;=ECODE_3F{J}&amp;lt;='T19' OR 'T36'&amp;lt;=ECODE_3F{J}&amp;lt;='T50' 
     	OR 'T51'&amp;lt;=ECODE_3F{J}&amp;lt;='T65' OR ECODE_3F{J} IN ('T71', 'T73', 'T74','T76') 
     	OR ECODE_5F{J}='T1491' OR ECODE_4F{J} IN ('T750', 'T752', 'T753') THEN CAUSE_E{J}=1;
	 	ELSE CAUSE_E{J}=0;


		** ASSIGN ADVERSE EFFECTS/UNDERDOSING AND SQUELAE AS NON-VALID ECODE;
    	IF 'T36'&amp;lt;= ECODE_3F{J} &amp;lt;='T50' AND SUBSTR(ECODE_6F{J},6,1) IN ('5','6') THEN CAUSE_E{J}=0;       
    	IF ECODE_4F{J} IN ('T369','T379','T399','T414','T427','T439','T459','T479','T499')          
		AND  SUBSTR(ECODE_6F{J},5,1) IN ('5','6') THEN  CAUSE_E{J}=0;                                

		IF ENCTE{J}='S' THEN CAUSE_E{J}=0;   	                                                                   
    END;


    **IF A VALID EXTERNAL CAUSE CODE IS FOUND IN ANY DIAGNOSIS OR EXTERNAL CAUSE FIELDS==&amp;gt; INJURY CASE;
    IF INJDX=0 THEN DO;
       IF SUM(OF CAUSE_D1-CAUSE_D12)&amp;gt;0 OR SUM(OF CAUSE_E1-CAUSE_E2)&amp;gt;0 THEN INJDX=1;    
	END;                                                                                 

	** REMOVE NON-INJURY CASES TO CREATE INJURY CASE SUBSET;
	IF INJDX=0 THEN DELETE;

	END;

RUN;
		%end;
	%end;
%mend joinfile2;
%joinfile2(16,17);  &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I run that code, I get these errors (repeated four times for each of the 2 x 2 prefix-year combinations I have).&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;80: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 80-322: Expecting a variable name.
76: LINE and COLUMN cannot be determined.
NOTE: NOSPOOL is on. Rerunning with OPTION SPOOL might allow recovery of the LINE and COLUMN where the error has occurred.
ERROR 76-322: Syntax error, statement will be ignored.
NOTE: Line generated by the invoked macro "JOINFILE2".
165        ,1) IN ('5','6') THEN INJDX=0;                                IF ENCT1="S" THEN INJDX=0;   ** REMOVE NON-INJURY CASES TO
165      ! CREATE FINAL INJURY CASE SUBSET (EXCLUDES SEQUELAE);  IF INJDX=0  THEN DELETE;   END;   ELSE   DO;
                                                                                            ___
                                                                                            161

ERROR 161-185: No matching DO/SELECT statement.

NOTE: The SAS System stopped processing this step because of errors.
WARNING: The data set WORK.PDD16_2 may be incomplete.  When this step was stopped there were 0 observations and 284 variables.
NOTE: DATA statement used (Total process time):
      real time           0.11 seconds
      cpu time            0.06 seconds
      &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I realize this is a long post.&amp;nbsp; I greatly appreciate your forbearance and any thoughts you have on how I can get this to work!&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 00:14:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549452#M152458</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2019-04-09T00:14:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Programming with IF-THEN-DO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549453#M152459</link>
      <description>&lt;P&gt;I suspect that the following is not what you want:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if &amp;amp;&amp;amp;type&amp;amp;j. = "pdd" then &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Here SAS is trying to translate&amp;nbsp;&lt;CODE class=" language-sas"&gt;&amp;amp;&amp;amp;type&amp;amp;j. into a SAS dataset variable, but I think that you actually want the macro variable, is this correct? This is why you get&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Variable pdd is uninitialized
Variable ed is uninitialized&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;If so, then you need to use quotations on both sides.&amp;nbsp;&lt;/CODE&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if "&amp;amp;&amp;amp;type&amp;amp;j." = "pdd" then&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;You are also mixing data step code with macro code. So, the %put will always print, no matter if the if case is true or not. Try to add:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 1 = 2 then do;
%put Impossible!!! ;
end;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So, if you want to see where you are, use put instead of %put.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 00:47:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549453#M152459</guid>
      <dc:creator>heffo</dc:creator>
      <dc:date>2019-04-09T00:47:13Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Programming with IF-THEN-DO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549476#M152474</link>
      <description>&lt;P&gt;1) AS you use macro program, if you add OPTION SPOOL you'll get better chance to locate error line in the log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2) In the log there is&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;ERROR 161-185: No matching DO/SELECT statement.&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; pay attention to next lines in your code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;	** REMOVE NON-INJURY CASES TO CREATE FINAL INJURY CASE SUBSET (EXCLUDES SEQUELAE);
	IF INJDX=0  THEN DELETE;
		END;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp; The END; statement has no DO or SELECT and should be canceled.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 04:57:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549476#M152474</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-04-09T04:57:36Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Programming with IF-THEN-DO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549497#M152485</link>
      <description>&lt;P&gt;Pack your two different calculations in two separate macros, and then let a data step handle the execution:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  x = "pdd ed";
  max = countw(x);
  call symput("max",max);
  do i = 1 to max;
    call symput("type"||left(put(i, 1.)),scan(x,i));
  end;
run;

%let startyr=16;
%let endyr=17;

data _null_;
  do j = 1 to &amp;amp;max.;
    do i=&amp;amp;startyr. to &amp;amp;endyr.; 
      if resolve(cats('&amp;amp;type',put(j,best.))) = "pdd"
      then call execute ('%nrstr(%macro1))';
      else call execute ('%nrstr(%macro2))'; 
    end;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2019 06:18:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549497#M152485</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-04-09T06:18:50Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Programming with IF-THEN-DO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549704#M152567</link>
      <description>&lt;P&gt;Thanks, heffo, for your time.&amp;nbsp; Your suggestion helped solve the smaller problem of getting the test code to run, with one adaptation:&amp;nbsp; I had to put "yes" and "nope" in quotation marks.&amp;nbsp; So:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
	x = "pdd ed";
	max = countw(x);
	do i = 1 to max;
		call symput("max",max);
		call symput("type"||left(put(i, 1.)),scan(x,i));
	end;
run;

%put &amp;amp;max &amp;amp;type1 &amp;amp;type2;



%macro joinfile(startyr,endyr);
data _null_;
	%do j=1 %to &amp;amp;max.;
		%do i=&amp;amp;startyr. %to &amp;amp;endyr.; 


	if "&amp;amp;&amp;amp;type&amp;amp;j." = "pdd" then 
		do;
			put "yes";
		end;
	else 
		do;
			put "nope"; 
		end;

		%end;
	%end;
run ;

%mend joinfile;
%joinfile(16,17);&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 09 Apr 2019 16:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549704#M152567</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2019-04-09T16:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Programming with IF-THEN-DO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549705#M152568</link>
      <description>&lt;P&gt;Thanks, Shmuel, for your time.&amp;nbsp; I will use the option SPOOL ON and see if that helps.&amp;nbsp; I did eliminate the END, but the code still doesn't work.&amp;nbsp; It may be that the nested conditional structures are too complex, and it looks like there are other problems as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll look more closely at the log.&amp;nbsp; Again, I appreciate the help.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 16:50:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549705#M152568</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2019-04-09T16:50:07Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Programming with IF-THEN-DO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549707#M152570</link>
      <description>Thank you very much, Kurt Bremser. This code also works, with a logic distinct from my original code. I wish I could accept more than one suggestion as a solution!</description>
      <pubDate>Tue, 09 Apr 2019 16:51:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549707#M152570</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2019-04-09T16:51:53Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Programming with IF-THEN-DO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549712#M152574</link>
      <description>&lt;P&gt;Some comments on coding in general:&lt;/P&gt;
&lt;PRE&gt;data _null_;
	x = "pdd ed";
	max = countw(x);
	do i = 1 to max;
		&lt;FONT color="#3366ff"&gt;&lt;STRONG&gt;call symput("max",max);&lt;/STRONG&gt;&lt;/FONT&gt;
		call symput("type"||left(put(i, 1.)),scan(x,i));
	end;
run;
&lt;/PRE&gt;
&lt;P&gt;The highlighted line returns the exact same result each iteration of the loop. This particular example won't mean much but habitual use of such will create very inefficient code that may be measurable later.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Letting macro variables "fall into" the middle of another macro is asking for hard to debug problems later.&lt;/P&gt;
&lt;PRE&gt;%macro joinfile(startyr,endyr);
data _null_;
	%do j=1 %to &lt;FONT color="#3366ff"&gt;&lt;STRONG&gt;&amp;amp;max.&lt;/STRONG&gt;&lt;/FONT&gt;;
		%do i=&amp;amp;startyr. %to &amp;amp;endyr.; 

	if &lt;FONT color="#3366ff"&gt;&lt;STRONG&gt;&amp;amp;&amp;amp;type&amp;amp;j.&lt;/STRONG&gt;&lt;/FONT&gt; = "pdd" then 
		do;
			%put yes;
		end;
	else 
		do;
			%put nope; 
		end;

	%end;
%end;
run ;

%mend joinfile;
&lt;/PRE&gt;
&lt;P&gt;The highlighted macro variables would be much better off passed as parameters. The type likely passed as a single variable an parsed.&lt;/P&gt;
&lt;P&gt;For your example may be something like:&lt;/P&gt;
&lt;PRE&gt;%macro joinfile(startyr,endyr,x);
   %let max = %sysfunc(countw(&amp;amp;x.));

data _null_;
	%do j=1 %to &amp;amp;max.;
		%do i=&amp;amp;startyr. %to &amp;amp;endyr.; 
      %let type = %scan(&amp;amp;x.,&amp;amp;j.);
	if "&amp;amp;type." = "pdd" then 
		do;
			put "i= &amp;amp;i." +1 "type= &amp;amp;type." +1 "yes";
		end;
	else 
		do;
			put  "i= &amp;amp;i." +1 "type= &amp;amp;type." +1"nope"; 
		end;

	%end;
%end;
run ;
%mend;

%joinfile(16,17, pdd ed); 
&lt;/PRE&gt;
&lt;P&gt;I added the &amp;amp;I and &amp;amp;type variables to the PUT statement so you could tell what condition was satisfied easier.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:01:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549712#M152574</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-09T17:01:45Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional Programming with IF-THEN-DO</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549717#M152579</link>
      <description>Thanks for the tips, ballardw. This (and the other suggestions I received) is exactly the sort of feedback I need to get better at SAS.</description>
      <pubDate>Tue, 09 Apr 2019 17:09:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Conditional-Programming-with-IF-THEN-DO/m-p/549717#M152579</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2019-04-09T17:09:44Z</dc:date>
    </item>
  </channel>
</rss>

