The SAS Output Delivery System and reporting techniques

How to conditionally recode / replace a value that shows in ODS Output

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 7
Accepted Solution

How to conditionally recode / replace a value that shows in ODS Output

Hi,

 

I create a SAS report using the DATA step with my code below. In the report, I want to recode the value of -8.00 to a dash

' - ' to indicate no observations. Below is a portion of the report. How can I do that in SAS?

 

Thanks

 

DATA SCORED.&FORM.Combined_Statistics_R;

SET SCORED.&FORM.Combined_Statistics_R (RENAME=(Key_char=Key));

file print header=H notitles;

PUT @1 "Item Number:" @14 seq @20 "Accession Number:" @38 ACN @55 "N of Response Opts:" @75 Number_of_Options/

@4 "Correct Answer:" @20 Key/

@4 'P value:' @13 pvalue @21 'Pt Biserial:' @34 Pt_Biserial @42 "Bench Item Delta:" @60 Bench_Item_Delta //

@10 'Response Opt:' @26 "A" @36 "B" @46 "C" @56 "D" @66 "E" @76 'Total N of PPL'/

@10 'N of PPL:' @26 N_of_ppl_A @36 N_of_ppl_B @46 N_of_ppl_C @56 N_of_ppl_D @66 N_of_ppl_E @76 Total_N/

@10 'P Value:' @26 PValue_A @36 PValue_B @46 PValue_C @56 PValue_D @66 PValue_E/

@10 'Pt Biserial:' @26 PT_Biserial_A @36 PT_Biserial_B @46 PT_Biserial_C @56 PT_Biserial_D @66 PT_Biserial_E/

@10 'Mean Score:' @26 Mean_Score_A @36 Mean_Score_B @46 Mean_Score_C @56 Mean_Score_D @66 Mean_Score_E////;

return;

H: Put @1 "Item analysis for &FORM that has &NUMBER MCQs."////;

RUN;

 


 

Item analysis for Exam_1922 that has 120 MCQs.                                                                                                                      
                                                                                                                                                                    
                                                                                                                                                                    
                                                                                                                                                                    
                                                                                                                                                                    
                                                                                                                                                                    
         Response Opt:   A         B         C         D         E         Total N of PPL                                                                           
         N of PPL:       0         0         0         1         365       367                                                                                      
         P Value:        0.000     0.000     0.000     0.003     0.995                                                                                              
         Pt Biserial:    -8.00     -8.00     -8.00     -.059     0.078                                                                                              
         Mean Score:     0.000     0.000     0.000     63.00     77.31            

Accepted Solutions
Solution
‎05-12-2017 01:15 PM
Super User
Posts: 5,082

Re: How to conditionally recode / replace a value that shows in ODS Output

A few steps are required;  First, before the DATA step:

 

options missing='-';

 

You can change the -8 to missing, but still need this statement to get it to print as a dash.  After the DATA step is over, you can consider whether or not you want to reset with:

 

options missing='.';

 

Next, in the DATA step (right after the SET statement), you need to transform your data.  This means first collecting all the variables that might need to be changed:

 

array eights {*} PT_Biserial_:;

 

You can add to the list if more variables belong there.

 

Then immediately change the values before the PUT statement writes them out:

 

do i=1 to dim(eights);

   if eights{i}=-8 then eights{i}=.;

end;

 

That should do it.

 

View solution in original post


All Replies
Super User
Super User
Posts: 7,401

Re: How to conditionally recode / replace a value that shows in ODS Output

A set of conditionals after the set:

if <variable>=-0.800 then <variable>="-";

However if they are numeric values then you cant just put dashes in as it has to be valid numbers.  Can I question why your creating such an output, it seems overly complicated to create, and would be a real pain in the neck for anyone further to use that?

Occasional Contributor
Posts: 7

Re: How to conditionally recode / replace a value that shows in ODS Output

Thanks. I'll try this. This is a portion of an item analysis report that provides more item analysis information than the PROC CORR procedure, and the format of the report is better because we need to view results for a large number of test questions across the fewest number of pages possible. The statistics are generated by a SAS macro that can analyze data for an arbitrary number of multiple choice test questions. Regards, Aaron 

Solution
‎05-12-2017 01:15 PM
Super User
Posts: 5,082

Re: How to conditionally recode / replace a value that shows in ODS Output

A few steps are required;  First, before the DATA step:

 

options missing='-';

 

You can change the -8 to missing, but still need this statement to get it to print as a dash.  After the DATA step is over, you can consider whether or not you want to reset with:

 

options missing='.';

 

Next, in the DATA step (right after the SET statement), you need to transform your data.  This means first collecting all the variables that might need to be changed:

 

array eights {*} PT_Biserial_:;

 

You can add to the list if more variables belong there.

 

Then immediately change the values before the PUT statement writes them out:

 

do i=1 to dim(eights);

   if eights{i}=-8 then eights{i}=.;

end;

 

That should do it.

 

Occasional Contributor
Posts: 7

Re: How to conditionally recode / replace a value that shows in ODS Output

This solution did exactly what I wanted it to do, with very few additional statements. Thanks!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 162 views
  • 0 likes
  • 3 in conversation