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):
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 🙂
Can you please provide a larger screen capture so I can read the text? It's too small right now.
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.
thank you so much.
For YY then I should say if not "Nære kontakter"? I am quite new in SAS
I fixed it!
The only thing is that the text ">10%" etc. do not come with just the color
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.
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
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.
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?
define ledigtid/noprint;
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.