/* HAVE */
/* First import the csv data file */
data work.import;
infile "P:\TEMP\DummyData.csv"
delimiter = "|"
missover
dsd
firstobs=2;
informat DummyName $50.;
informat wknr 2.;
informat yr_range $9.;
informat nodum 10.;
format DummyName $50.;
format wknr 2.;
format yr_range $9.;
format nodum 10.;
input
DummyName
wknr
yr_range
nodum
;
run;
/* Then this is how many distinct graphs we should produce: in this case 8 */
proc sql;
create table imp_sg_tot as
select distinct DummyName from work.import
order by DummyName;
quit;
/* Data which should be used to show on graphs */
PROC SQL;
CREATE table IMP_SG AS
SELECT *, max(wknr) as maxwk, min(wknr) as minwk, max(nodum) AS maxaant
FROM work.IMPORT
GROUP BY DummyName,yr_range
ORDER BY DummyName,yr_range,wknr;
QUIT;
/* WANT */
/*
1 sgplot graph for each _n_ in dataset "IMP_SG_TOT" (n=1 to 8) from dataset "IMP_SG".
On the horizontal axis there should show: wknr
On the vertical axis: nodum
Data should be grouped by(?) DummyName.
And all yr_ranges show as lines (different color/type lines) on this particular graph.
So.. for DummyName on _N_=1 (='Dum- & Dat') there should be 2 graphs like this:
-first graph shows 5 lines for yr-ranges: 2016-2017, 2017-2018, 2018-2019, 2019-2020 and 2020-2021.
-and second graph shows only 1 line for yr-range: 2022-2023
I don't want to use sgpanel. Only sgplot. Is this possible?
I hope you guys understand what i mean... and above all: i hope someone can help me out with graphing!
I really don't have that much experience with graphing the data.... :-(
Thanks in Advance!
*/
Well it says it all in my SAS-code actually...
I hope someone can help me out! 🙂
And the data i use is as attachment: csv-file
Edit:
Sorry.. forget something!
Why I am making extra columns (with max & min wknr and max nodum) is because I want the graphs to show the min and max wknr on the axis automatically based on this column values! Idem. for the max nodum on the vertical axis.
I hope you guys/girls understand what I mean. 🙂
Edit2:
@ballardw yes, I mean they are limits of the axis! Thank you!
@Reeza that are the graphs I want yes! But only 2 graphs per DummyName:
1) with all the years (except for 2022-2023) (so you get 5 vlines in 1 graph)
2) only 2022-2023 year (so you get 1 vline in 1 graph)
This is my picture - please note: it contains only year 2016-2017, but it must contain 5 vlines/groups of years.
Hopefully it is clear to you guys now? If not, please let me know! I will clear it more for you if needed. I'm still learning... 🙂
If the code I posted seems correct, just add a WHERE statement to filter the years of interest.
Show a single sample graph, your explanation and data don't quite align especially with SAS terms. Specifically the reference lines....
data work.import;
infile "/home/fkhurshed/Demo1/DummyData.csv"
delimiter = "|"
missover
dsd
firstobs=2;
informat DummyName $50.;
informat wknr 2.;
informat yr_range $9.;
informat nodum 10.;
format DummyName $50.;
format wknr 2.;
format yr_range $9.;
format nodum 10.;
input
DummyName
wknr
yr_range
nodum
;
run;
/* Then this is how many distinct graphs we should produce: in this case 8 */
proc sql;
create table imp_sg_tot as
select distinct DummyName from work.import
order by DummyName;
quit;
/* Data which should be used to show on graphs */
PROC SQL;
CREATE table IMP_SG AS
SELECT *, max(wknr) as maxwk, min(wknr) as minwk, max(nodum) AS maxaant
FROM work.IMPORT
GROUP BY DummyName
ORDER BY DummyName,yr_range,wknr;
QUIT;
/* 1 sgplot graph for each _n_ in dataset "IMP_SG_TOT" (n=1 to 8) from dataset "IMP_SG". */
/* On the horizontal axis there should show: wknr */
/* On the vertical axis: nodum */
/* Data should be grouped by(?) DummyName. */
/* And all yr_ranges show as lines (different color/type lines) on this particular graph. */
/* */
/* So.. for DummyName on _N_=1 (='Dum- & Dat') there should be 2 graphs like this: */
/* */
/* -first graph shows 5 lines for yr-ranges: 2016-2017, 2017-2018, 2018-2019, 2019-2020 and 2020-2021. */
/* -and second graph shows only 1 line for yr-range: 2022-2023 */
proc sgplot data=imp_sg;
by dummyName;
series x=wknr y=nodum / group = yr_range;
refline minwk / axis=y;
refline maxaant / axis=y;
run;
I would suggest that you start with this and see if anything actually needs changing:
proc sgplot data=work.imp_sg; by dummyname notsorted; scatter x=wknr y=nodum/group=yr_range; run;
Actually you may not even need the other data sets but might need either NOTSORTED on the By statement if you use the first set or sort the data.
When you use a By group processing the default behavior for Sgplot is that the axis ranges are calculated for each graph. So your max and min values may not be needed.
Your really did not specify what type of graph you expected, series, scatter, needle, vector or something else. The bit about those values on the axis were not very clear. Were they supposed to be limits of the axis, special tick marks added, reference lines or what?
Sorry guys for being so messy with the data and not being so clear!
I will try to clear my text by putting an examples of graph I want..hopefully it will clear things out.
Please see my Opening Post! I will add it there, just a moment!
And thank you guys for helping out!!!
If the code I posted seems correct, just add a WHERE statement to filter the years of interest.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.