Hello there !
I cannot seem to fix a broken scatter plot. For an unknown reason, the points on the graph are going up (instead of up and down).
This is the code I am running
proc sgplot data=cardata;
scatter x=year y=age_adjusted_rate;
run;
Any ideas why?
Do this:
data cardata;
infile reffile dlm=',' dsd truncover;
input
Sex :$15.
Race :$15.
State :$20.
Ethnicity :$10.
Age_Group :$15.
First_Year
Last_Year
Cause_of_Death :$50.
Year
Deaths
Population
Crude Rate
Age_Adjusted_Rate
;
run;
to read the numbers as numbers.
Show your log.
Is there a format applied to the library?
What happens if you plot the following:
proc sgplot data=sashelp.class;
scatter x=height y=weight;
run;
@AbhilashS wrote:
Hello there !
I cannot seem to fix a broken scatter plot. For an unknown reason, the points on the graph are going up (instead of up and down).
This is the code I am running
proc sgplot data=cardata;
scatter x=year y=age_adjusted_rate;
run;
Any ideas why?
Hi Reeza
Here is the log from the code I ran
I ran the code you suggested and the plot worked. What does that tell you?
It tells me the issue is not with SAS but with your data, so that's when you know to check the data types and formats.
You can convert a character variable to a numeric as follows though you should really back up and ensure you read it in properly from the start.
data temp;
set have;
age_adjusted_rate_num = input(age_adjusted_rate, 12.1);
run;
proc sgplot data=temp;
scatter x=year y=age_adjusted_rate_num;
run;
Perhaps your Y variable is probably character instead of numeric? That can happen if you (mis)read the data from an Excel spreadsheet.
To check, run
proc contents data=cardata;
run;
and look at the type of the Age_Adjusted_Rate variable.
Hi Rick
Yes you are right. It is a CHARACTER. Is there a way to change them to NUMERIC?
How did that data arrive in SAS (import from external file, read from foreign database, ...)?
Then you should give us an example of the csv file. Either copy/paste a few lines into a window opened with the </> button (open the file with an editor, not with Excel!), or attach it to a post.
FILENAME REFFILE '/folders/myfolders/sas_datasets/results.csv'; PROC IMPORT DATAFILE=REFFILE DBMS=CSV OUT=WORK.cardata replace; RUN;
Thanks Kurt.
I have attached both the CSV file I am using and the code I ran.
Do this:
data cardata;
infile reffile dlm=',' dsd truncover;
input
Sex :$15.
Race :$15.
State :$20.
Ethnicity :$10.
Age_Group :$15.
First_Year
Last_Year
Cause_of_Death :$50.
Year
Deaths
Population
Crude Rate
Age_Adjusted_Rate
;
run;
to read the numbers as numbers.
A simple trick to change this to a numeric variable is to add zero:
data NEW;
set OLD;
rate2=age_adjusted_rate+0;
run;
Exactly the same as https://communities.sas.com/t5/Graphics-Programming/Change-Scatter-Plot-Axis-Values/m-p/648398#M1990...
This appears with two different people posting such to be homework. Bring to the instructor's attention that the data file is poorly structured CSV for Proc Import to read. If all of the values are quoted then Proc Import will think the data is character: Example rows.
"Sex","Race","State","Ethnicity","Age Group","First Year","Last Year","Cause of Death","Year","Deaths","Population","Crude Rate","Age-Adjusted Rate" "Both Sexes","All Races","United States","Both","All Ages","1999","2016","Unintentional MV Traffic, Occupant","1999","18326","279040238","6.57","6.55966083710955" "Both Sexes","All Races","United States","Both","All Ages","1999","2016","Unintentional MV Traffic, Occupant","2000","18649","282171936","6.61","6.59229940420289"
Hi Ballardw
Thank you for pointing this out. This is actually a self-guided statistics course with this data specifically being generated from the CDC website. There is no live instructor but I will try and email your points to the course creator. It has been a challenge as the tutorials do not anticipate problems like the one I have had so I am quite thankful to the help I am getting.
Thank you Reeza and KurtB for your patience and help.
Eureka !
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.
Find more tutorials on the SAS Users YouTube channel.