<?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 formatting within a data step inside a MACRO in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594008#M15611</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/291927"&gt;@Alex_Peterson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Tom, I do see what you are saying, but I will need to make calculations on the variables that are dates, so they will need to be some numeric date format. For example, my data set could look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var5&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Bill&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12/12/2011&amp;nbsp; &amp;nbsp; 01/03/1987&amp;nbsp; &amp;nbsp;Sean&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Matt&lt;/P&gt;
&lt;P&gt;Mike&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/1991&amp;nbsp; &amp;nbsp;09/29/2017&amp;nbsp; &amp;nbsp;Carol&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Deborah&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want my program to go through each of these variables in a macro (with the var&amp;amp;I. in a %DO loop method), and when there is no letter detected in one of the values in that variable, to assign that variable the DDMMYY10 format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is a totally different problem.&amp;nbsp; You will need to read the ENTIRE dataset and derive a flag for each variable, as a whole, to indicate what type you want to convert it into. Then use that information to generate the code to make the conversion.&amp;nbsp; You will need to make a decision what to do when 9 out of 10 observations for VAR2 look like dates.&amp;nbsp; Should the variable become a date? Or stay as a character string? What about when only 60% look like dates? 40%?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So before trying to make a MACRO to generate the code you want to run you need to figure what code you need to run.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be easier to just dump the data to delimited text file and let PROC IMPORT do the guessing for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv temp;
data _null_;
  set have ;
  file csv ;
  put var1-var5;
run;
proc import datafile=csv dbms=csv 
  out=want replace 
;
  getnames=no;
run;&lt;/CODE&gt;&lt;/PRE&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>Fri, 04 Oct 2019 02:25:17 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2019-10-04T02:25:17Z</dc:date>
    <item>
      <title>Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593981#M15599</link>
      <description>&lt;P&gt;I am creating variables within a macro %do loop inside a data step, kinda like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;     %DO I = 1 %TO 5;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NEW_VAR&amp;amp;I. = "Hello";
     %END;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This successfully creates variables named new_var1 through new_var5, all filled with “Hello.” What I’m trying to figure out is if you can do &lt;EM&gt;conditional&lt;/EM&gt; formatting. For example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;      %DO I = 1 %TO 5;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF &amp;amp;I. &amp;lt; 5 THEN DO;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NEW_VAR&amp;amp;I. = "12/12/2010";&amp;nbsp; * This automatically makes the variables type CHAR;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; IF &amp;amp;I. = 5 THEN DO;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; NEW_VAR&amp;amp;I. = 18608; * the number equivalent of the date I want;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FORMAT NEW_VAR&amp;amp;I. MMDDYY10.; * I want new_var5 to be a different format than the others;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; END;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; %END;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This gives me the error: “The format $MMDDYY was not found or could not be loaded.”&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This seemingly would only arise if NEW_VAR5 was somehow already defined as CHAR. &amp;nbsp;It appears that NEW_VAR5 is already initialized deep in SAS somewhere with a CHAR format, which is causing me issues. I tried doing MACRO %IF statements instead, which actually does solve this problem, but the reason I don’t want to switch to MACRO IF statements is because functions like %ANYALPHA don’t exist in natural SAS macro functions (unlike %UPCASE(), %SUBSTR(), etc).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas for how to solve this problem? Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 23:15:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593981#M15599</guid>
      <dc:creator>Alex_Peterson</dc:creator>
      <dc:date>2019-10-03T23:15:54Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593984#M15600</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You have an ordinary data step IF test that you intend to dynamically assign formats.&amp;nbsp; But FORMAT statements are not "executable" in a data step.&amp;nbsp; So they are honored regardless of whether they are in an IF ... THEN DO ... structure.&amp;nbsp; So you can assign conflicting formats to a variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need to use MACRO %IF ... %THEN %DO, as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro chk;
%DO I = 1 %TO 5;
            %IF &amp;amp;I. &amp;lt; 5 %THEN %DO;
                  NEW_VAR&amp;amp;I. = "12/12/2010";  * This automatically makes the variables type CHAR;
            %END;

            %IF &amp;amp;I. = 5 %THEN %DO;
                  NEW_VAR&amp;amp;I. = 18608; * the number equivalent of the date I want;
                  FORMAT NEW_VAR&amp;amp;I. MMDDYY10.; * I want new_var5 to be a different format than the others;
            %END;
%END;
%mend chk;
dm 'clear log';
options mprint;
data new;
  %chk ;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you set OPTIONS MPRINT prior to your data step, you would see relevant notes in the sas log.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 23:41:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593984#M15600</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-03T23:41:58Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593985#M15601</link>
      <description>&lt;P&gt;Thank you for this answer! Is there any other method to accomplish this (no matter how inefficient) ? As I mentioned, I am trying to avoid using macro %IF statements because I cannot do something like %IF ANYALPHA(variable) %THEN %DO;.&amp;nbsp; ANYALPHA is not a compatible function for MACRO %IF.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 23:51:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593985#M15601</guid>
      <dc:creator>Alex_Peterson</dc:creator>
      <dc:date>2019-10-03T23:51:19Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593988#M15602</link>
      <description>&lt;P&gt;take a look at this solution and see if the char works for you&lt;/P&gt;
&lt;P&gt;&lt;A href="https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567407#M159555" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/Check-Macro-character-variable-value-inside-a-if-condition/m-p/567407#M159555&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 00:14:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593988#M15602</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-10-04T00:14:41Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593989#M15603</link>
      <description>&lt;P&gt;Show us how you want to use the ANYALPHA function.&amp;nbsp;&amp;nbsp; Perhaps it can be successfully used (like most normal sas functions) when embedded in the macro %SYSFUNC() function.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 00:17:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593989#M15603</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-10-04T00:17:56Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593999#M15606</link>
      <description>&lt;P&gt;This is ultimately the type of thing I'm hoping to accomplish:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;I have a data set called A1, with the variables VAR1 - VAR500. The variables are either dates or names, all in CHAR format.  

%MACRO test;
       DATA A2;
              set A1;
              %DO I = 1 %TO 500;
                     IF ANYALPHA(VAR&amp;amp;I.) THEN DO;
                            NEW_VAR&amp;amp;I. = VAR&amp;amp;I.;
                     END;
                     ELSE DO;
                            NEW_VAR&amp;amp;I. = input(VAR&amp;amp;I., MMDDYY10.);
                            FORMAT NEW_VAR&amp;amp;I. MMDDYY10.;
                     END;
              %END;
       RUN;
%MEND test;&lt;/PRE&gt;</description>
      <pubDate>Fri, 04 Oct 2019 01:45:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/593999#M15606</guid>
      <dc:creator>Alex_Peterson</dc:creator>
      <dc:date>2019-10-04T01:45:04Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594001#M15607</link>
      <description>&lt;P&gt;That doesn't make sense.&amp;nbsp; If you attach a format to a variable it is attached to the VARIABLE, not any particular VALUE that the variable might have on some individual observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The only reason to try to do what it looks like your code is trying to do would to standardize the way the dates a represented in the character variable NEW_VAR&amp;amp;i. So values like '1/5/19' would get converted to '01/05/2019'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;new_var&amp;amp;i = var&amp;amp;i;
if 0 &amp;lt; lengthn(new_var&amp;amp;i) &amp;lt;=10 then
  if not missing(input(new_var&amp;amp;i,??mmddyy10.)) then
  new_var&amp;amp;i = put(input(new_var&amp;amp;i,mmddyy10.),mmddyy10.)
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 01:59:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594001#M15607</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-04T01:59:08Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594006#M15609</link>
      <description>&lt;P&gt;Tom, I do see what you are saying, but I will need to make calculations on the variables that are dates, so they will need to be some numeric date format. For example, my data set could look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var5&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Bill&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12/12/2011&amp;nbsp; &amp;nbsp; 01/03/1987&amp;nbsp; &amp;nbsp;Sean&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Matt&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/1991&amp;nbsp; &amp;nbsp;09/29/2017&amp;nbsp; &amp;nbsp;Carol&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Deborah&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want my program to go through each of these variables in a macro (with the var&amp;amp;I. in a %DO loop method), and when there is no letter detected in one of the values in that variable, to assign that variable the DDMMYY10 format.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 02:12:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594006#M15609</guid>
      <dc:creator>Alex_Peterson</dc:creator>
      <dc:date>2019-10-04T02:12:32Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594008#M15611</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/291927"&gt;@Alex_Peterson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Tom, I do see what you are saying, but I will need to make calculations on the variables that are dates, so they will need to be some numeric date format. For example, my data set could look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var5&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Bill&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12/12/2011&amp;nbsp; &amp;nbsp; 01/03/1987&amp;nbsp; &amp;nbsp;Sean&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Matt&lt;/P&gt;
&lt;P&gt;Mike&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/1991&amp;nbsp; &amp;nbsp;09/29/2017&amp;nbsp; &amp;nbsp;Carol&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Deborah&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want my program to go through each of these variables in a macro (with the var&amp;amp;I. in a %DO loop method), and when there is no letter detected in one of the values in that variable, to assign that variable the DDMMYY10 format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That is a totally different problem.&amp;nbsp; You will need to read the ENTIRE dataset and derive a flag for each variable, as a whole, to indicate what type you want to convert it into. Then use that information to generate the code to make the conversion.&amp;nbsp; You will need to make a decision what to do when 9 out of 10 observations for VAR2 look like dates.&amp;nbsp; Should the variable become a date? Or stay as a character string? What about when only 60% look like dates? 40%?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So before trying to make a MACRO to generate the code you want to run you need to figure what code you need to run.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be easier to just dump the data to delimited text file and let PROC IMPORT do the guessing for you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;filename csv temp;
data _null_;
  set have ;
  file csv ;
  put var1-var5;
run;
proc import datafile=csv dbms=csv 
  out=want replace 
;
  getnames=no;
run;&lt;/CODE&gt;&lt;/PRE&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>Fri, 04 Oct 2019 02:25:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594008#M15611</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-04T02:25:17Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594010#M15612</link>
      <description>&lt;P&gt;Sounds like you're cleaning up data.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What types are you current variables? What makes you think you need macro's at all here by the way, have data step functions not worked so far?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You cannot just assign a variable format by the way, you need to first convert it into a new variable and then apply a format to that data set.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If your data is as clean as shown any reason to not use the / as a delimiter?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/291927"&gt;@Alex_Peterson&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Tom, I do see what you are saying, but I will need to make calculations on the variables that are dates, so they will need to be some numeric date format. For example, my data set could look like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;var1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;var4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var5&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;Bill&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 12/12/2011&amp;nbsp; &amp;nbsp; 01/03/1987&amp;nbsp; &amp;nbsp;Sean&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Matt&lt;/P&gt;
&lt;P&gt;Mike&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 01/01/1991&amp;nbsp; &amp;nbsp;09/29/2017&amp;nbsp; &amp;nbsp;Carol&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Deborah&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want my program to go through each of these variables in a macro (with the var&amp;amp;I. in a %DO loop method), and when there is no letter detected in one of the values in that variable, to assign that variable the DDMMYY10 format.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 02:27:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594010#M15612</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-10-04T02:27:24Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594019#M15613</link>
      <description>&lt;P&gt;Tom, thanks for your reply. Assume the data is for sure fully date in DD/MM/YYYY style or fully names. So no checking required. In fact, assume I'm only reading the first observation to determine format assignments. The fundamental question is whether, in a MACRO, you can assign a different format to a dynamically created variable conditioned on whether or not the value in that variable contains a letter.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know there are other ways I could change the format of these variables. For example, with PROC IMPORT, or just doing a new data step and writing something like FORMAT NEWVAR1-NEWVAR15&amp;nbsp; NEWVAR43-NEWVAR65 MMDDYY10.;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The question is whether you can accomplish this using IF THEN logic, and having the ANYALPHA function as the condition. The reason it needs to be in a MACRO is because I need the ability to create variables with the form NEWVAR&amp;amp;I. in a %DO loop.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 02:50:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594019#M15613</guid>
      <dc:creator>Alex_Peterson</dc:creator>
      <dc:date>2019-10-04T02:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594083#M15622</link>
      <description>&lt;P&gt;Before you make a macro you need to make a program. Then generalize it so you can generate the program with a macro.&lt;/P&gt;
&lt;P&gt;So if you are ok with only testing one observation it will be easier.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let var1=0;
data _null_;
  set have (obs=1);
  if anyalpha(VAR1) then call symputx('VAR1',1);
run;

data want;
  set have ;
%if &amp;amp;var1 = 1 %then %do;
  new_var1 = var1 ;
%end;
%else %do;
  new_var1 = input(var1,mmddyy10.);
  format new_var1 mmddyy10.;
%end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I will leave it as an exercise for you how to extend this to multiple variables.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 12:43:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594083#M15622</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-04T12:43:11Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional formatting within a data step inside a MACRO</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594113#M15628</link>
      <description>&lt;P&gt;One possible key to resolving this:&amp;nbsp; what is in the data set A1?&amp;nbsp; If it already contains new_var5 (defined as character) that would cause a problem.&amp;nbsp; You may need to get rid of any existing variable names that begin with "new_var":&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;set A1 (drop=new_var: );&lt;/P&gt;</description>
      <pubDate>Fri, 04 Oct 2019 14:15:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Conditional-formatting-within-a-data-step-inside-a-MACRO/m-p/594113#M15628</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-04T14:15:18Z</dc:date>
    </item>
  </channel>
</rss>

