BookmarkSubscribeRSS Feed
Quartz | Level 8

Hi everyone,


I have a task which I couldn't tackle. I have a data set that includes patient's ID and several variables coding patient's outcome performance on different scales before, during and after an intervention. The grade of performance is coded from 0 to 4. Performance outcomes are partially missing for some patients. 

I want to build a line chart that shows the change in the percentage of patients that have a performance grade 3 or 4 before, during and after the outcome.


My data look like this:


Data x;
input ID test1before test1during test1after test2before test2during test2after ... .. testNafter;
1 1 2 3 1 3 3 ... 3;
2 . 1 2 1 4 4 ... 4;
3 3 4 4 1 3 3 ... 2;

I have a number of difficulties. I think the best way is to make a new data set that contains the percentage of performance grade 3 or 4 for a each test on before, during and after the intervention, but I did not find the right procedure. Such data set will look like this:


Test     Before     During     After

Test1   30%        55%        50%

Test2   20%       43%        38%

Test3  ....

Test N


The percentage need to be calculated after excluding missing values.


Can you please help me?


Super User

I might suggest the Test number be just that unless you have much more information involved than "Test1".

The overall data for graphing is likely to look more like but you don't mention what your "line chart" should look like. What would the xaxis on your chart represent? The test number?


Test Period   Value

Test1 Before 30%

Test1 During 55%

Test1 After    50%


Are asking for help on calculating percentages? What would the numerator and denominator be for the percentages?


Note your cards statements are incorrect as you cannot have the ; ending them and the data step would end with Run, not end.


Here is my guess as to what you might be attempting:

Data x;
input ID before1 during1 after1 before2 during2 after2 ;
   array t before: during: after: ;
   /* create 1/0 coded values, mean will be decimal percentage*/
   do i= 1 to dim(t);
      t[i] = t[i] in (3,4);
   drop i;
1 1 2 3 1 3 3 
2 . 1 2 1 4 4 
3 3 4 4 1 3 3 

proc summary data=x;
   var before: during: after: ;
   output out= xsum (drop=_type_ _freq_) mean=;

data plot;
   set xsum;
   array b before: ;
   array d during: ;
   array a after:  ;
   do Test= 1 to dim(b);
   keep test when value;

proc sgplot data=plot;
   series x=test y=value /group=when;
   format value percent8.1;



Secure your spot at the must-attend AI and analytics event of 2024: SAS Innovate 2024! Get ready for a jam-packed agenda featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events.


Register by March 1 to snag the Early Bird rate of just $695! Don't miss out on this exclusive offer. 


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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 2 in conversation