BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Jonison
Fluorite | Level 6

Hello, expert.

 

I have code below:

 

data WORK.Prediction_results;
set WORK.QUERY_FOR_PREDICTION;
FP1_5CC = ' ';                     /* adding new char column*/
run;

 

proc report data=WORK.Prediction_results;

define LSL /display;

define USL /display;
define FP1_5CC /computed;
compute FP1_5CC;
if LSL >45 and USL < 80 then do;
FP1_5CC = 'Green';   /*give char 'green' to FP1_5CC when it meets the conditions*/
call define(_col_,'style','style={background=greenpuff}');
end;
else do;
call define(_col_,'style','style={background=redpuff}');
end;

endcomp;
run;

QUIT;

 

 

When I run this, no characters shown in green cells, and note is 'green' is invalid numeric data;

 

I think the defination of char column didnot work, would you please suggest on this? thanks 

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

You are getting that error because you tried to assign a string to a variable that your told PROC REPORT to create as numeric.

You have to tell the COMPUTE statement that you want to make a character variable, otherwise it will make a numeric variable.

https://communities.sas.com/t5/SAS-Procedures/Creating-a-character-variable-using-Proc-Report/td-p/3...

 

There is no need to add the variable before the PROC REPORT step since you are computing it.  If you want to use an existing variable in the code of your compute block but not print if in the report use the NOPRINT option in the DEFINE statement fro the variable.

 

If you do want to add a character variable to a dataset in a data step make sure to set it long enough for all of the values it might hold.  Better to use LENGTH statement to define the variable.  If you don't define the variable SAS will have to guess how you want it defined based on how you first use it.

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

What is redpuff and greenpuff? If you fix that, does the program work then?

 

What is the purpose of variable FP1_5CC ? If you assign the value 'Green' to it then the cells in PROC REPORT will contain the text 'Green'. Is that what you want?

 

The specific error you get, 'invalid numeric data' ... can you show us the LOG so we can see that for ourselves? Please paste the log into the window that appears when you click on the </> icon. DO NOT SKIP THIS STEP.

 

--
Paige Miller
Tom
Super User Tom
Super User

You are getting that error because you tried to assign a string to a variable that your told PROC REPORT to create as numeric.

You have to tell the COMPUTE statement that you want to make a character variable, otherwise it will make a numeric variable.

https://communities.sas.com/t5/SAS-Procedures/Creating-a-character-variable-using-Proc-Report/td-p/3...

 

There is no need to add the variable before the PROC REPORT step since you are computing it.  If you want to use an existing variable in the code of your compute block but not print if in the report use the NOPRINT option in the DEFINE statement fro the variable.

 

If you do want to add a character variable to a dataset in a data step make sure to set it long enough for all of the values it might hold.  Better to use LENGTH statement to define the variable.  If you don't define the variable SAS will have to guess how you want it defined based on how you first use it.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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
  • 2 replies
  • 1501 views
  • 0 likes
  • 3 in conversation