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;
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?
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;
@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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.