Provide a plot where the x-axis is year and the y-axis is the number of UFO sightings according to this dataset, the question for me there are no year and number of ufo sightings variables directly, how can I fix it and make a graph?
I import the data and use proc sgplot to do it , but i don't know how to get the year and number of UFO sightings.
proc import datafile="\\tsclient\home\desktop\UFO.csv"
out=UFO_1;
run;
proc sgplot data=UFO_1;
scatter x=year y=UFO_sightings
run;
Are you actually asking questions? It doesn't seem like you are.
It seems like you are giving us a homework assignment (which we will not do for you)
Sorry about that, I just changed and give the question that I have with the problem.
Bests.
Stella.
Seems like we would have to see the dataset in order to answer this, and you haven't shown us the dataset.
Furthermore, you might want to try doing this simple task in SAS yourself, and if you are having trouble we can help you out. We are not going to do your homework for you.
So sorry about that, it is my first time to do that , so may have some problems and now I changed it.
Bests
Stella
1. Your PROC IMPORT does not appear correct - there is no DBMS statement and you say it's a CSV file but uploaded an XLSX file?
Make sure the log shows a correct import ant that examining the data set shows a correct data set. XLSX files are not downloaded by a lot of users.
2. To get the number per year, you can use a summary procedure to first calculate the frequency. You can use PROC FREQ or MEANS to get the number per year. PROC FREQ is probably more clear in this example. You would need to save this to a data set so that you can use it in your next step. See an example of PROC MEANS and a format on a date variable here:
https://gist.github.com/statgeek/0cae5568752959b035516d6ac07a20fb
You can use YEAR() on a date to get the year portion or you can use formats as illustrated in the post above - you can run that code directly in your program.
3. Plot the data from step 2, using SGPLOT, your code looks technically correct.
I've outlined the steps above, but obviously not the full solution but if you tackle each individual problem one at a time its solvable.
@Stellachen wrote:
Provide a plot where the x-axis is year and the y-axis is the number of UFO sightings according to this dataset, the question for me there are no year and number of ufo sightings variables directly, how can I fix it and make a graph?
I import the data and use proc sgplot to do it , but i don't know how to get the year and number of UFO sightings.
proc import datafile="\\tsclient\home\desktop\complete.csv" out=UFO_1; run; proc sgplot data=UFO_1; scatter x=year y=UFO_sightings run;
It's just a count of the number of records isn't it?
Your TABLE statement would just have the date, unless you needed to account for multiple sightings somehow but I'm going to guess not.
@Stellachen wrote:
Thanks a lot! I understand what's you means but one question is I didn't know use what variable to calculate the frequency.
Seems like you ar having the genral problem of getting 0 into a count. There is a good procedure in ETS that creates missing values in a timeseries as what you want. Look at proc timeseries. It will create 0's when there are no observations in a regular time series. Other option os to create all your years in a table using a do loop to get 0 sightings for each year. Count the sightings by year. merge this with the all 0's and plot that.
One way is to apply an appropriate format to a date variable for the X axis variable, if a date YEAR4. or if the variable is a date time then DTYEAR4.
Then a VBAR statement in Proc SGPLOT with option STAT=Freq will show a count of records against the Yaxis.
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.
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.