I am creating variables within a macro %do loop inside a data step, kinda like this: %DO I = 1 %TO 5;
NEW_VAR&I. = "Hello";
%END; 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 conditional formatting. For example: %DO I = 1 %TO 5;
IF &I. < 5 THEN DO;
NEW_VAR&I. = "12/12/2010"; * This automatically makes the variables type CHAR;
END;
IF &I. = 5 THEN DO;
NEW_VAR&I. = 18608; * the number equivalent of the date I want;
FORMAT NEW_VAR&I. MMDDYY10.; * I want new_var5 to be a different format than the others;
END;
%END; This gives me the error: “The format $MMDDYY was not found or could not be loaded.” This seemingly would only arise if NEW_VAR5 was somehow already defined as CHAR. 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). Any ideas for how to solve this problem? Thanks!
... View more