I have a table of name Proposal in which there is a column name value_cd. This column has values of some check boxes that will be checked in my webout report. I want to check all the check-boxes whose relevant value is in this column.
table:Proposal
value_cd
New_par
Rev_par
Here is my code
data _null_;
put numberOfObservationes=;
set work.Proposal nobs=numberOfObservationes;
file _webout;
if value_cd eq "New_par" then put '<input type=checkbox disabled checked /> <label>New Parameter</label> <br /> <hr /> ';
else put '<input type=checkbox disabled /> <label>New Parameter</label> <br /> <hr /> ';
if value_cd eq "Rev_par" then put '<input type=checkbox disabled checked /> <label>Revised Parameter</label> <br /> <hr /> ';
else put '<input type=checkbox disabled /> <label>Revised Parameter</label> <br /> <hr /> ';
if value_cd eq "New_pro" then put '<input type=checkbox disabled checked /> <label>New Process</label> <br /> <hr /> ';
else put '<input type=checkbox disabled /> <label>New Process</label> <br /> <hr /> ';
run;
I want to print a check box only once in my report and it should be checked or unchecked based on the values of column value_cd of my table but when a value is not equal in if condition it runs the else statement and code is printing check boxes till count of value_cd.
How can i print check boxes only once based on the of value_cd.
I want this
checkbox checked New Parameter *if-statement;
checkbox checked Revised Parameter *if-statement;
checkbox New Process *else-statement;
upper code is printing output below
checkbox checked New Parameter *if-statement;
checkbox Revised Parameter *else-statement;
checkbox New Process *else-statement;
checkbox New Parameter *else-statement;
checkbox checked Revised Parameter *if-statement;
checkbox New Process *else-statement;
What is happening row-wise, 6 checkboxes:
row-1: logic-1-output logic-2-output logic-3-output
row-2: logic-1-output logic-2-output logic-3-output
What is wanted, 3 checkboxes:
row-1: track-logic-1-for-true track-logic-2-for-true track-logic-3-for-true
row-2: track-logic-1-for-true track-logic-2-for-true track-logic-3-for-true
last-row: output-based-on-tracked-logics
Here is one approach
Track the value_cd states that occur over all the rows, then perform the output.
data _null_;
put numberOfObservationes=;
set work.Proposal nobs=numberOfObservationes end=last_row;
array boxes[3] _temporary_; * 1st slot is for New_par, 2nd for Rev_par, etc..;
* track for true using OR;
boxes[1] = boxes[1] or (value_cd eq "New_par");
boxes[2] = boxes[2] or (value_cd eq "Rev_par");
boxes[3] = boxes[3] or (value_cd eq "New_pro");
if last_row then do;
if boxes[1]
then checked_attribute='checked';
else checked_attribute='';
put '<input type=checkbox disabled ' checked_attribute '/> <label>New Parameter</label> <br /> <hr /> ';
if boxes[2]
then checked_attribute='checked';
else checked_attribute='';
put '<input type=checkbox disabled ' checked_attribute '/> <label>Revised Parameter</label> <br /> <hr /> ';
if boxes[3]
then checked_attribute='checked';
else checked_attribute='';
put '<input type=checkbox disabled ' checked_attribute '/> <label>New Process</label> <br /> <hr /> ';
end;
run;
NOTE: The above code is essentially pivoting the value_cd data from a column to a single row.
In a DATA Step variable values are normally reset to missing at the top on the implicit loop (in this case when you go from row-1 to row-2). In order to track a condition from row to row a variable should not be reset by the implicit loop.
There are a couple of ways the reset can be avoided:
RETAIN
variable_temporary_
arraySET
within an explicitly coded do while
or do until
loop.