BookmarkSubscribeRSS Feed
KelvinG
Calcite | Level 5

Hello Everyone,

 

I'm working on automating a report generation process that involves data extraction, transformation, and conditional output formatting, but I'm still learning SAS programming. I've been experimenting with SAS Macros, but I'm having some trouble and would appreciate some advice from this experienced group.

 

This is my situation:

 

Data Sources: Several datasets kept in various libraries provide the data. Although the structure of each dataset is similar, department-specific variables may be included.
Condition: The report format needs to be slightly modified based on the department, which is a crucial variable in the datasets. For instance, whereas some departments require summary visuals, others require detailed tables.
Output: Each department's report should be saved in a separate folder, and the final output should contain both PDF and Excel files.

 

Problems I'm Having:

 

Macros that are dynamic: I'm having trouble adding conditional logic for various output formats to the macro I've started writing that loops through the department names.
Visual Exporting: Even though I know how to use PROC SGPLOT to create graphs, I'm not sure how to combine them with tables in a single PDF.
Folder management: Using department names to automate the creation and saving of reports into designated directories.


Questions for the Public:

 

  • How should macros be organized for a report this dynamic?
  • Are there any particular steps or settings in SAS that make exporting tables and graphics together easier?
  • Does anyone have any examples of successful conditional formatting in macros?

I would be very grateful for any resources, sample code, or advice. Thanks in advance for your help and support.

 

Regards

Kelvinccsp

1 REPLY 1
Kurt_Bremser
Super User

Step 1: create non-macro code for at least two departments.

Step 2: identify differences and similarities.

Step 3: replace department-specific code parts (e.g. variable lists) with macro variables, and wrap department-specific steps in %IF-%THEN %DO-%END

Step 4: decide how department-specific information to create macro variables are best supplied to the code

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 45 views
  • 1 like
  • 2 in conversation