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

 

here is the work i did so far, is anyone can help me where is the problem and how can i fix it, thank you very much!

 

Screen Shot 2022-01-18 at 11.46.03 PM.png

Screen Shot 2022-01-18 at 11.45.56 PM.png

  

1 ACCEPTED SOLUTION

Accepted Solutions
Panagiotis
SAS Employee

Not sure exactly what you are looking for since you are vague. My guess is you want to see the the obs value by Substance in a scatter plot? Do you care about the observation number? Also in the future can you paste code to create the sample data to make it easier for us to test code. 

 

Like @Konu-Tec  said, you probably need to 'melt' the data from wide to narrow. Sometimes called transpose. With SAS you can use PROC TRANPOSE.

 

Here is sample data I made using your image:

 

data outdata;
	input Substance $ obs1-obs4;
	datalines;
	1 29 28 23 26
	2 17 25 24 19
	3 17 16 21 22
	4 18 20 25 24
;
run;

 

 

Then transpose/melt the data from wide to narrow using PROC TRANPOSE:

 

proc transpose data=outdata 
			   out=narrowdata(rename=(col1=Value))
			   name=ObsNumber;
	by substance;
run;

proc print data=narrowdata;
run;

Tranposed.png

 

 

Now that the data is in narrow format. Use the SCATTER statement in SGPLOT.

 

proc sgplot data=narrowdata;
	scatter x=Substance y=Value;
quit;

Default Scatter.png

 

 

 

I don't like the default image, so you can begin to explore different options and statements in SGPLOT. I'm also not sure exactly what you are looking for, but here is a start:

title color=charcoal justify=left height=14pt "Value by Substance";
proc sgplot data=narrowdata;
	scatter x=Substance y=Value /
			group=Substance
			markerattrs=(symbol=circleFilled);
	keylegend / noborder title="";
	yaxis values=(0 to 35 by 5);
quit;
title;

FinalScatter.png

 

 

 

- Peter

 

View solution in original post

4 REPLIES 4
Panagiotis
SAS Employee

Not sure exactly what you are looking for since you are vague. My guess is you want to see the the obs value by Substance in a scatter plot? Do you care about the observation number? Also in the future can you paste code to create the sample data to make it easier for us to test code. 

 

Like @Konu-Tec  said, you probably need to 'melt' the data from wide to narrow. Sometimes called transpose. With SAS you can use PROC TRANPOSE.

 

Here is sample data I made using your image:

 

data outdata;
	input Substance $ obs1-obs4;
	datalines;
	1 29 28 23 26
	2 17 25 24 19
	3 17 16 21 22
	4 18 20 25 24
;
run;

 

 

Then transpose/melt the data from wide to narrow using PROC TRANPOSE:

 

proc transpose data=outdata 
			   out=narrowdata(rename=(col1=Value))
			   name=ObsNumber;
	by substance;
run;

proc print data=narrowdata;
run;

Tranposed.png

 

 

Now that the data is in narrow format. Use the SCATTER statement in SGPLOT.

 

proc sgplot data=narrowdata;
	scatter x=Substance y=Value;
quit;

Default Scatter.png

 

 

 

I don't like the default image, so you can begin to explore different options and statements in SGPLOT. I'm also not sure exactly what you are looking for, but here is a start:

title color=charcoal justify=left height=14pt "Value by Substance";
proc sgplot data=narrowdata;
	scatter x=Substance y=Value /
			group=Substance
			markerattrs=(symbol=circleFilled);
	keylegend / noborder title="";
	yaxis values=(0 to 35 by 5);
quit;
title;

FinalScatter.png

 

 

 

- Peter

 

tmorr
Fluorite | Level 6

thank you so much! so here is another question that if i try to get the ANOVA table, i try the code:

 

proc anova data = outdata;
class Substance;
model Substance = value;
run;

 

but there is a error, 

Panagiotis
SAS Employee

Glad it helped.

 

For your other question you should explore or post in the statistical procedures forum here: https://communities.sas.com/t5/Statistical-Procedures/bd-p/statistical_procedures.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

Tips for filtering data sources in SAS Visual Analytics

See how to use one filter for multiple data sources by mapping your data from SAS’ Alexandria McCall.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 983 views
  • 2 likes
  • 3 in conversation