I am new to SAS. I have started a macro that creates a file each time a Rectype has an outlier identified in the control chart. I would like to create a new file each RecType has a outlier identifed in the shewhart statement for the most recent month. I have tried adding the variable(&RecType) in the ODS File statement, however I have had no luck. Any suggestions?
ODS PDF FILE="C:\Desktop\OUTLIERS2.pdf" &RecType; STYLE=OCEAN;
%Let Heading=RecType
proc shewhart data=work.OUTLIERS2; xchart _SUBX_* MONYEAR /sigmas=2; run;
RUN;
ODS PDF CLOSE;
ods listing;
Not sure what you are trying to do, is this all your code? Does the rectype come from the output of the shewhart procedure or is it something you put in by hand. The definition of the macro variable needs to appear before the actual use. So you could do:
%let rectype=recordtype;
%let headin=This is a &rectype. heading;
You have other errors there though. For instance you have a semicolon after your &recType macro reference which means the style is invalid. Macro variables are delimited by a dot, e.g. &RecType. style=ocean.
As for the line:
ODS PDF FILE="C:\Desktop\OUTLIERS2.pdf" &RecType; STYLE=OCEAN;
What is RecType to be as there is no option on an ods line (except select/exclude)?
Perhaps provide a clear example with test data of what you have and what you want.
Hi,
If you really are new to SAS, be careful with how soon you start writing macros. The (main) purpose of the macro language is to generate SAS code. Usually it makes sense to spend time writing (and debugging) your own SAS code until you are comfortable with that, before adding in the complexity of automated code generation. There is plenty you can do with SAS without worrying about macros. Even non-macro ways to do code generation.
That said, if you are sure you want to dive in to macros, sometimes a way to start is to write your SAS code first and get it working, and then convert it into a macro.
--Q.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.