BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NevermoreRedres
Obsidian | Level 7

Hello everyone, hope you'all doing ok!

I've been messing around with SAS Graph Tasks trying to lear how to use then, however i don't think they will help me for what i need in this moment, lemme show you first:

 

DATA analisemean;
infile cards dlm='09'x dsd truncover;
input mean (mean2014 mean2015 mean2016 mean2017 mean2018 mean2019) (:time.);
format mean2014--mean2019 time8.;
CARDS;
a_to_b	04:47:32	04:40:54	04:36:07	04:07:07	03:55:44	03:59:19
b_to_c	02:26:01	03:27:40	03:36:04	03:55:09	04:38:44	05:00:16
c_to_d	02:22:59	01:43:49	01:28:21	01:51:59	01:17:46	01:13:54
d_to_e	02:33:03	02:46:13	02:27:37	02:21:11	02:16:04	02:39:59
f_to_f	01:57:31	01:20:01	01:18:16	01:05:33	00:57:53	00:59:44
Run;

 

 

So, i have this table from my data, collecting the arimetic average of intervals of time (a_to_b, b_to_c etc) from 2014 to 2019, as you can see on the name of the variables.

The problem i'm dealing is i don't know how to make SAS understand that i want the variables on the hh/mm/ss format.... also i don't know how to make a graph without using the SAS tasks.

 

What i had in mind was a Time Series Graph, with the time intervals (a_to_b...f_to_f) in the X axis, an scale that goes from 1h to 6h on the Y axis (because de highest hour the table has is 05:00:16) and six lines with diferent colours for each year (2014...2019). 

Does anyone know how i can do that? Also if you know, could you explain to me wich part of the code does what, i'm trying to lear (unless it takes a long time to write, don't want to take a lot of time of you guys). And i'm also open for critics, if you think another tipe of graph would be better than the one i had in mind, i'm all ears.

Thank you in advance!

1 ACCEPTED SOLUTION

Accepted Solutions
maguiremq
SAS Super FREQ

Here's a way to do it. I've tried to explain in my comments, so please let me know if you have any questions, or if anything seems off. Also, note that when you run it that the log says that it replaces the format is replaced by an auto-generated format. Also, there's certainly a more efficient way to do the DATALINES statement, but I was getting tired of it failing. Your original DATALINES didn't work for me.

 

data analisemean_c;
infile datalines delimiter = "," missover;
/*input mean :$6. mean2014 - mean2019 :time9.;*/
input mean :$6. mean2014 :time9. mean2015 :time9. mean2016 :time9. mean2017 :time9. mean2018 :time9. mean2019 :time9.;
format mean2014 - mean2019 time9.;
datalines;
a_to_b,04:47:32,04:40:54,04:36:07,04:07:07,03:55:44,03:59:19
b_to_c,02:26:01,03:27:40,03:36:04,03:55:09,04:38:44,05:00:16
c_to_d,02:22:59,01:43:49,01:28:21,01:51:59,01:17:46,01:13:54
d_to_e,02:33:03,02:46:13,02:27:37,02:21:11,02:16:04,02:39:59
f_to_f,01:57:31,01:20:01,01:18:16,01:05:33,00:57:53,00:59:44
;
run;

/* Transpose to get in long format. */

proc transpose data = analisemean_c 				/* Transpose our original data */
	out = analisemean_t (rename = (col1 = value)); 	/* renamed default "COL1" to value just for ease of interpretation */
		by mean; 									/* We want to transpose it by the "mean" label (a_to_a, etc.) */
		var mean2014-mean2019; 						/* These are the variables you want to be in one column */
run;

proc sgplot data = analisemean_t;	/* Plotting our transposed data. */
	series 	x = mean 				/* This is your x-axis - make it the label a_to_a, etc. */
			y = value / 			/* This is the transposed column containing the values fro mean2014 - mean2019. Notice the slash (/) */
			markers					/* Adds circles to graph. */
			group = _name_;			/* This assigns a color to each group. */
run;

maguiremq_0-1617020946744.png

 

View solution in original post

6 REPLIES 6
maguiremq
SAS Super FREQ

Here's a way to do it. I've tried to explain in my comments, so please let me know if you have any questions, or if anything seems off. Also, note that when you run it that the log says that it replaces the format is replaced by an auto-generated format. Also, there's certainly a more efficient way to do the DATALINES statement, but I was getting tired of it failing. Your original DATALINES didn't work for me.

 

data analisemean_c;
infile datalines delimiter = "," missover;
/*input mean :$6. mean2014 - mean2019 :time9.;*/
input mean :$6. mean2014 :time9. mean2015 :time9. mean2016 :time9. mean2017 :time9. mean2018 :time9. mean2019 :time9.;
format mean2014 - mean2019 time9.;
datalines;
a_to_b,04:47:32,04:40:54,04:36:07,04:07:07,03:55:44,03:59:19
b_to_c,02:26:01,03:27:40,03:36:04,03:55:09,04:38:44,05:00:16
c_to_d,02:22:59,01:43:49,01:28:21,01:51:59,01:17:46,01:13:54
d_to_e,02:33:03,02:46:13,02:27:37,02:21:11,02:16:04,02:39:59
f_to_f,01:57:31,01:20:01,01:18:16,01:05:33,00:57:53,00:59:44
;
run;

/* Transpose to get in long format. */

proc transpose data = analisemean_c 				/* Transpose our original data */
	out = analisemean_t (rename = (col1 = value)); 	/* renamed default "COL1" to value just for ease of interpretation */
		by mean; 									/* We want to transpose it by the "mean" label (a_to_a, etc.) */
		var mean2014-mean2019; 						/* These are the variables you want to be in one column */
run;

proc sgplot data = analisemean_t;	/* Plotting our transposed data. */
	series 	x = mean 				/* This is your x-axis - make it the label a_to_a, etc. */
			y = value / 			/* This is the transposed column containing the values fro mean2014 - mean2019. Notice the slash (/) */
			markers					/* Adds circles to graph. */
			group = _name_;			/* This assigns a color to each group. */
run;

maguiremq_0-1617020946744.png

 

NevermoreRedres
Obsidian | Level 7
Hello maguiremq, thank you so much for your help and the comments, it taught me a lot. Yeah i know these datalines can get a little clunky when dealing with hh/mm/ss format without the dates, but it is what i could gather for the researsh 😕
If you know of an document or link that could teach me more about graph making, it would also help a lot!
Thank you again and have a good day 🙂
maguiremq
SAS Super FREQ

I think this should be a very helpful for the SGPLOT procedure. It is very thorough and presents a lot of options.

https://support.sas.com/resources/papers/proceedings10/154-2010.pdf 

NevermoreRedres
Obsidian | Level 7
Wow, it has a lot of good examples! Thank you one more time!
ballardw
Super User

@NevermoreRedres wrote:
Hello maguiremq, thank you so much for your help and the comments, it taught me a lot. Yeah i know these datalines can get a little clunky when dealing with hh/mm/ss format without the dates, but it is what i could gather for the researsh 😕
If you know of an document or link that could teach me more about graph making, it would also help a lot!
Thank you again and have a good day 🙂

https://support.sas.com/en/knowledge-base/graph-samples-gallery.html

has links to many graphs including data in data steps and fully worked code. Images of completed graphs may lead you to what you want, or display elements of what you want and up to you to combine them.

 

Start with the SGPLOT and SGPANEL and then move to GTL and SGRENDER.

NevermoreRedres
Obsidian | Level 7
Hello again ballardw! Hope you're doing ok.
I'm looking at it and it really has a lot of examples and easy explanation, thank you!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 6 replies
  • 842 views
  • 6 likes
  • 3 in conversation