SAS Programming

DATA Step, Macro, Functions and more
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
RAVI2000
Lapis Lazuli | Level 10

For example, a variable LABCAT has values like "Hematology", "Chemical", "Urinalysis".....    and variable lab parameter PARAM has values like "WBC", "RBC", "BASOPHILS", ...so on like 100. I have 100 values for PARAM. 

Example Look-up Table:

PARAMN       PARAM                   PARAMCD            ATYPE            LBCAT               LBTESTCD

1                Potassium)mmol/L)     K                           num             CHEMISTRY          K

2                Albumin(g/L)                ALB                      num             CHEMISTRY          ALB

3                Creatinine(umol/L)       CREAT                 num             CHEMISTRY          CREAT

4                Basophils(10^9L)         BASO                   num             HEMATOLOGY      BASO

5                Prothrobin Time           PT                         num             HEMATOLOGY      PT

6                Color                            COLOR                 char             URINALYSIS          COLOR

7                pH                                PH                         char             URINALYSIS          PH

.........

.

.

.

 

How do I create macro  where it directly takes the PARAM values for 100 different values automatically and creates the output table. In simple, I want to create a macro in such a way that I want to call that macro and I should get all the 100 outputs/ reports/ tables.

For your reference I am also attaching a mock table output that I want for 100 tables.

Capture.PNG

 

Please let me know if you need any additional information.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Shmuel
Garnet | Level 18

1) Suppose you have just one PARAM. Can you writ a program to create a report as wanted?

2) You don't need a macro; just create the report BY PARAM.

3) You did not supply the full observation info - you miss numeric values to be used in the 

     report. What is XX ?

View solution in original post

3 REPLIES 3
Shmuel
Garnet | Level 18

1) Suppose you have just one PARAM. Can you writ a program to create a report as wanted?

2) You don't need a macro; just create the report BY PARAM.

3) You did not supply the full observation info - you miss numeric values to be used in the 

     report. What is XX ?

RAVI2000
Lapis Lazuli | Level 10
Sorry, I have mistakenly accepted it as solution. I have just provide a mock shell. Mock shells are just a blue print of how the output table should look like. It is just a blueprint. XX would be numeric values.
Reeza
Super User

UCLA introductory tutorial on macro variables and macros
https://stats.idre.ucla.edu/sas/seminars/sas-macros-introduction/

Tutorial on converting a working program to a macro
This method is pretty robust and helps prevent errors and makes it much easier to debug your code. Obviously biased, because I wrote it 🙂 https://github.com/statgeek/SAS-Tutorials/blob/master/Turning%20a%20program%20into%20a%20macro.md

Examples of common macro usage
https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Ap...

 

Your question is too generic, please provide more details.

 


@RAVI2000 wrote:

For example, a variable LABCAT has values like "Hematology", "Chemical", "Urinalysis".....    and variable lab parameter PARAM has values like "WBC", "RBC", "BASOPHILS", ...so on like 100. I have 100 values for PARAM. 

Example Look-up Table:

PARAMN       PARAM                   PARAMCD            ATYPE            LBCAT               LBTESTCD

1                Potassium)mmol/L)     K                           num             CHEMISTRY          K

2                Albumin(g/L)                ALB                      num             CHEMISTRY          ALB

3                Creatinine(umol/L)       CREAT                 num             CHEMISTRY          CREAT

4                Basophils(10^9L)         BASO                   num             HEMATOLOGY      BASO

5                Prothrobin Time           PT                         num             HEMATOLOGY      PT

6                Color                            COLOR                 char             URINALYSIS          COLOR

7                pH                                PH                         char             URINALYSIS          PH

.........

.

.

.

 

How do I create macro  where it directly takes the PARAM values for 100 different values automatically and creates the output table. In simple, I want to create a macro in such a way that I want to call that macro and I should get all the 100 outputs/ reports/ tables.

For your reference I am also attaching a mock table output that I want for 100 tables.

Capture.PNG

 

Please let me know if you need any additional information.

 

 


 

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 1166 views
  • 0 likes
  • 3 in conversation