I am trying to create a graph similar to the one below (1st image) and pulled their dataset to try to recreate. I thought I'd use "proc sgplot" to try to reproduce it but I am having trouble. My y-axis is all over the place with data as you can see (2nd image). How can I get it to look more like the one I am trying to recreate? This is my code so far.
proc sgplot data=ocww3;
where(data_source= "CDPH Drinking Water and Radiation Lab");
Scatter x=Sample_Date y=Concentration;
Run;Original
My graph
Obviously, SAS take "Concentration" as a character variable, and doesn't use its numeric meaning at all. You have to convert "Concentration" into a numeric variable first. By the way, you may also need a series statement to plot a line.
data ocww4;
set ocww3;
concn=input(concentration,best.);
run;
proc sgplot data=ocww4;
where(data_source= "CDPH Drinking Water and Radiation Lab");
scatter x=sample_date y=concn;
series x=sample_date y=concn;
Run;
/*
It looks like your Y variable "Concentration" is CHARACTER type.
Can you post your real data,so we can test your code ?
Here is an example you can refer to.
*/
proc sgplot data=sashelp.stocks(where=(stock="IBM")) noautolegend;
loess x=date y=close/markerattrs=(symbol=circlefilled) lineattrs=(color=black thickness=3);
run;
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!
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.