BookmarkSubscribeRSS Feed
mmea
Quartz | Level 8

Hi. with this code I made a proc report:

ods pdf notoc file="F:\Brugere\MMEA\hej.pdf" ;
proc report data=pdf1 nowd;
column teststed analysebeskrivelse dato Ledigtid;
define teststed/display;
define Ledigtid/ display;
compute Ledigtid;
    if Ledigtid = ">10%" then call define(_col_,"style","style={background=green}");
	if Ledigtid = "<10%" then call define(_col_,"style","style={background=red}"); 
endcomp;

run;

ods pdf close;


This code gives me this report (I have just cut out a small piece):

mmea_0-1608291675582.png

 

Is there a way to make new columns called fx "XX" and "YY". Column "XX" should contain all the values and colors of "Ledigtid" for those in "analysebeskrivelse" or "Teststed" who has the characters 'Nære kontakter' in the name. Anything else should be in "YY".

So i want the colors green and red match with the new columns I want to make based on the names from Teststed.

 

 

 

Does it make sense?

I hope so 🙂

10 REPLIES 10
PaigeMiller
Diamond | Level 26

Can you please provide a larger screen capture so I can read the text? It's too small right now.

--
Paige Miller
mmea
Quartz | Level 8

mmea_0-1608292420165.png

 

PaigeMiller
Diamond | Level 26

Untested code

 

 

ods pdf notoc file="F:\Brugere\MMEA\hej.pdf" ;
proc report data=pdf1 nowd;
column teststed analysebeskrivelse dato Ledigtid xx;
define teststed/display;
define Ledigtid/ display;
define xx/computed;
compute Ledigtid;
    if Ledigtid = ">10%" then call define(_col_,"style","style={background=green}");
	if Ledigtid = "<10%" then call define(_col_,"style","style={background=red}"); 
endcomp;
compute xx;
    if find(teststed,'Nære kontakter')>0 or find(analysebeskrivelse,'Nære kontakter')>0 then do;

        xx=ledigtid;
        if Ledigtid = ">10%" then call define(_col_,"style","style={background=green}");
	    if Ledigtid = "<10%" then call define(_col_,"style","style={background=red}"); 
    end;
endcomp;
run;

ods pdf close;

YY would be similar, so its a homework assignment for you.

 

--
Paige Miller
mmea
Quartz | Level 8

thank you so much.

For YY then I should say if not "Nære kontakter"? I am quite new in SAS

mmea
Quartz | Level 8

I fixed it!

The only thing is that the text ">10%" etc. do not come with just the color

PaigeMiller
Diamond | Level 26

Show us the code you used. Please paste your code as text into the box that appears when you click on the "running man" icon.

--
Paige Miller
mmea
Quartz | Level 8
ods pdf notoc file="F:\Brugere\MMEA\hey1.pdf" ;
proc report data=pdf1 nowd;
column teststed analysebeskrivelse dato Ledigtid Nærekontakter åbnetesttilbud;
define teststed/display;
define Ledigtid/ display;
define Nærekontakter/computed;
define åbnetesttilbud/computed;
compute Ledigtid;
    if Ledigtid = ">10%" then call define(_col_,"style","style={background=green}");
	if Ledigtid = "<10%" then call define(_col_,"style","style={background=red}"); 
endcomp;
compute Nærekontakter;
    if find(teststed,'Nære kontakter')>0 or find(analysebeskrivelse,'Nære kontakter')>0 then do;

        Nærekontakter=ledigtid;
        if Ledigtid = ">10%" then call define(_col_,"style","style={background=green}");
	    if Ledigtid = "<10%" then call define(_col_,"style","style={background=red}"); 
    end;
endcomp;
compute åbnetesttilbud;
if find(analysebeskrivelse,'Virustest')>0  then do;

        åbnetesttilbud=ledigtid;
        if Ledigtid = ">10%" then call define(_col_,"style","style={background=green}");
	    if Ledigtid = "<10%" then call define(_col_,"style","style={background=red}"); 
	

    end;
endcomp;

run;

ods pdf close;

I added the XX (called nære kontakter) and YY (åbne testetilbud)

I now get two new columns with the matching color basedon ledigtid, but i still want the text "<10%" etc in the new columns

PaigeMiller
Diamond | Level 26

Probably my mistake, I think you should have

compute Nærekontakter/character;

and

compute åbnetesttilbud/character;

 

If I may be so bold as to suggest a style improvement — I find that colors red and green are too bold and too overwhelming and makes the text hard to read. (Maybe you feel the same, or maybe not ... its a personal thing, I guess). So I use the following

"style={background=lightmoderategreen}"

and

"style={background=lightmoderatered}"

which makes a better looking output, in my opinion.

--
Paige Miller
mmea
Quartz | Level 8

Thank you so much it worked!

 

Do you know if you can add to you code, that you before running the PDF you want to remove some of the columns?

proc report data=pdf1 nowd;
column teststed analysebeskrivelse dato Ledigtid Nærekontakter åbnetesttilbud;
define teststed/display;
define Ledigtid/ display;
define Nærekontakter/computed;
define åbnetesttilbud/computed;
compute Ledigtid;
    if Ledigtid = ">10%" then call define(_col_,"style","style={background=green}");
	if Ledigtid = "<10%" then call define(_col_,"style","style={background=red}"); 
endcomp;
compute Nærekontakter/character;
    if find(teststed,'Nære kontakter')>0 or find(analysebeskrivelse,'Nære kontakter')>0 then do;

        Nærekontakter=ledigtid;
        if Ledigtid = ">10%" then call define(_col_,"style","style={background=green}");
	    if Ledigtid = "<10%" then call define(_col_,"style","style={background=red}"); 
    end;
endcomp;
compute åbnetesttilbud/character;
if find(analysebeskrivelse,'Virustest')>0  then do;

        åbnetesttilbud=ledigtid;
        if Ledigtid = ">10%" then call define(_col_,"style","style={background=green}");
	    if Ledigtid = "<10%" then call define(_col_,"style","style={background=red}"); 
	

    end;
endcomp;
run;

I use ledigtid and analysebeskrivelse in my statements, but I dont want them in my final report. Can I remove them?

PaigeMiller
Diamond | Level 26
define ledigtid/noprint;
--
Paige Miller

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 10 replies
  • 959 views
  • 1 like
  • 2 in conversation