BookmarkSubscribeRSS Feed
rebelde52
Fluorite | Level 6

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;

OriginalOriginalMy graphMy graph

2 REPLIES 2
Hao_Luo
SAS Alumni

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;
Ksharp
Super User
/*
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;

Ksharp_0-1679572403892.png

 

AI Navigator GIF.gif


Navigate AI governance with SAS tools for compliance and ethical AI practices. Try SAS Ai Navigator for free for the first six months.

Check it out on Microsoft Marketplace →

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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