BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
SAS_Question
Quartz | Level 8
/* 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... 🙂 
example.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

If the code I posted seems correct, just add a WHERE statement to filter the years of interest. 

View solution in original post

4 REPLIES 4
Reeza
Super User

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;

ballardw
Super User

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?

 

SAS_Question
Quartz | Level 8

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!!! 

Reeza
Super User

If the code I posted seems correct, just add a WHERE statement to filter the years of interest. 

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 4 replies
  • 646 views
  • 3 likes
  • 3 in conversation