BookmarkSubscribeRSS Feed
NWV
Calcite | Level 5 NWV
Calcite | Level 5

Hello, Today, using syntax I found in this forum, I used proc report and the call define terminology to create some custom colored output.  It worked fine, but I'm wondering if there was an easier way to do it for my dataset. I have 10 records, lab data each analyzed for 31 metals.  Each of the 31 metals is a variable, with a concentration listed for each sample.  I also have 31 flag variables 9one for each metal) indicating whether it was above or below a certain value.  I used the flag values (defined but not displayed) to create color coded output (traffic lighting). For example-- compute Tin; if (DQF_Tin="<") then call define ("Tin","style","style=[foreground=purple]"); else if (DQF_Tin="()") then call define ("Tin","style","style=[foreground=green]"); endcomp; compute Titanium; if (DQF_Titanium="<") then call define ("Titanium","style","style=[foreground=purple]"); else if (DQF_Titanium="()") then call define ("Titanium","style","style=[foreground=green]"); endcomp; There are 31 of these statements, one for each of the metals.  Was there an easier way?  I needed the 31 metal colums (plus a sample id) in the output, so I guess I have to define them all?  No shortcut? Thoughts appreciated. Thank you, Nicole

3 REPLIES 3
art297
Opal | Level 21

If you post your code, and a short datastep showing what you datafile looks like, I'm sure that someone could suggest a shortcut.

Reeza
Super User

Use a format in your call define. Check this paper out:

http://support.sas.com/resources/papers/proceedings10/153-2010.pdf

Vince provides an example using proc report and proc print.

The proc report example is almost identical to what you're doing.

art297
Opal | Level 21

I totally agree that you ought to look at Vince's paper and using the methods he suggests will save you quite a bit of time.

But, even though Vince probably knows more about the topic than anyone, you can still save some keystrokes by expanding his code even further.

For example, Vince uses the following statements in applying the formats:

array name(10) $31 ('Haemoglobin_Result' 'Haematocrit_Result' 'RBC_Result'

                      'WBC_Result' 'Lymphocytes_Result' 'Monocytes_Result'

                      'Neutrophils_Result' 'Eosinophils_Result' 'Basophils_Result'

                      'Platelets_Result');

 

array flag(10) Haemoglobin_Flag Haematocrit_Flag RBC_Flag WBC_Flag

                 Lymphocytes_Flag Monocytes_Flag Neutrophils_Flag Eosinophils_Flag

                 Basophils_Flag Platelets_Flag;

Actually, if you look at the data, Vince only used 10 of the 17 result and flag variables.  If you were actually interested in all of them, the keystrokes could be further reduced by using something like:

proc sql noprint;

  select quote(propcase(trim(name))) into :names

    separated by " "

      from dictionary.columns

         where libname eq "SAMPLE" and

               memname eq "LABRESULTS" and

               name like '%_result'

;

  select propcase(trim(name)) into :flags

    separated by " "

      from dictionary.columns

         where libname eq "SAMPLE" and

               memname eq "LABRESULTS" and

               name like '%_flag'

;

quit;

array name(17) $31 (&names.);

array flag(17) &flags.;

Of course, you could also use the same technique in a number of other places in his example code.

HTH,

Art

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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