BookmarkSubscribeRSS Feed
Ronein
Onyx | Level 15

Hello

I have summary data for each date with following information:

Total money paid by govername to people who applied for getting help(money).

Tota costs (The total amount that governemt spent on these payments)

PCT_Good (percent of people that recieved money)

PCT_bad (percent of people that didnt recieve money)

4 reasons for bad: PCT_Reason1,PCT_Reason2,PCT_Reason3,PCT_Reason4.

Please note that the limit money that can be paid in each date is 200 Million dollars.

I want to create the following charts in SAS:

chart1(Time series line chart with 2 lines and 1 Horizontal  line)

line1: Total_paid VS Date

line2: Total_costs VS Date

line3:Horizontal line on value 200

chart2(Time series bar chart with multiple bars)

For each date there will be a bar that will be devided into 5 parts:

PCT_Good (green color)

PCT_Reason1(Red color)

PCT_Reason2(pink color)

PCT_Reason3(blue color)

PCT_Reason4(grey color)

By looking at this chart we can understand proprtion of people (percentage) who recieved gelp and proprtion of people who didnt recieve help and the reasons.

 

Please see the raw data.

I also have a problem to create the summary data set with percent informats.

Data SummaryData;
Input Date :ddmmyy10.	Total_paid	Total_Costs	PCT_Good	PCT_Reason1	PCT_Reason2	PCT_Reason3	PCT_Reason4;
cards;
01/03/2021 170 180 60% 20% 10% 5%	5%
02/03/2021 180 185 65% 15% 15% 5%	 0%
03/03/2021 182 190 70% 10% 5%	10%	5%
04/03/2021 161 170 80% 5%	2.50% 2.50%	10%
05/03/2021 185 198 70% 10% 10% 10% 0%
;
run;


 

4 REPLIES 4
PaigeMiller
Diamond | Level 26

I haven't tested this, but something like this will work for #1, if that's not it exactly, it is close and you ought to be able to modify it as needed.

 

proc sgplot data=summarydata; 
    series x=date y=total_paid;
    series x=date y=total_costs;
    refline 200/axis=y;
run;

I don't really know what a "Time series bar chart" is. Can you show us an example?

 

 

--
Paige Miller
Ronein
Onyx | Level 15
https://www.vizwiz.com/2012/08/displaying-time-series-data-stacked.html

Please see first chart here.
It is an example to time series bar chart.
Each bar should be in same height ( that represents 100% of people) and then each bar should be devided into 5 groups by different colours: goods, reason1,reason2,
reason3,reason4
PaigeMiller
Diamond | Level 26

This is called a stacked bar chart in SAS. You would have to transpose the data first to get it into the proper form for PROC SGPLOT. Also, I didn't code up all of your reasons because I'm lazy, but you can fix this to handle all of the reasons.

 

Data SummaryData;
 informat Date ddmmyy10.	Total_paid	Total_Costs best8.	
     PCT_Good	PCT_Reason1	PCT_Reason2	PCT_Reason3	PCT_Reason4 percent.;
 Input Date Total_paid	Total_Costs	PCT_Good	PCT_Reason1	PCT_Reason2	PCT_Reason3	PCT_Reason4;
 format  PCT_Good	PCT_Reason1	PCT_Reason2	PCT_Reason3	PCT_Reason4 percent8.1;
cards;
01/03/2021 170 180 60% 20% 10% 5%	5%
02/03/2021 180 185 65% 15% 15% 5%	 0%
03/03/2021 182 190 70% 10% 5%	10%	5%
04/03/2021 161 170 80% 5%	2.50% 2.50%	10%
05/03/2021 185 198 70% 10% 10% 10% 0%
;
run;
data transposed;
    set summarydata;
    length type $ 10;
    type='Good'; value=pct_good; output;
    type='Reason 1'; value=pct_reason1; output;
    type='Reason 2'; value=pct_reason2; output;
    keep date type value;
run;

proc sgplot data=transposed;
    vbar date/group=type response=value groupdisplay=stack;
    format date ddmmyy.;
run;
--
Paige Miller
ballardw
Super User

@Ronein wrote:

Hello

Please see the raw data.

I also have a problem to create the summary data set with percent informats.

 Since "Informats" are used to read external data there would be very little need or use in creating an "informat" for summarized data which implies the data was already in SAS and you did something to summarize that data. A format is one thing.

But without showing how you summarize the raw data, as in example data, code to summarize and expected output it hard to provide examples.

 

And for your posted example did you try the PERCENT informat?

Data SummaryData;
 informat Date ddmmyy10.	Total_paid	Total_Costs best8.	
     PCT_Good	PCT_Reason1	PCT_Reason2	PCT_Reason3	PCT_Reason4 percent.;
 Input Date Total_paid	Total_Costs	PCT_Good	PCT_Reason1	PCT_Reason2	PCT_Reason3	PCT_Reason4;
 format  PCT_Good	PCT_Reason1	PCT_Reason2	PCT_Reason3	PCT_Reason4 percent8.1;
cards;
01/03/2021 170 180 60% 20% 10% 5%	5%
02/03/2021 180 185 65% 15% 15% 5%	 0%
03/03/2021 182 190 70% 10% 5%	10%	5%
04/03/2021 161 170 80% 5%	2.50% 2.50%	10%
05/03/2021 185 198 70% 10% 10% 10% 0%
;
run;

Remember if you want to a nice display format that you need to provide a FORMAT . The Percent format uses () to designate negative values so you need to provide a few more positions than you expect to display the values properly.

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