BookmarkSubscribeRSS Feed
Stellachen
Calcite | Level 5

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;
9 REPLIES 9
PaigeMiller
Diamond | Level 26

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)

--
Paige Miller
Stellachen
Calcite | Level 5

Sorry about that, I just changed and give the question that I have with the problem.

 

 

Bests.

Stella.

PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Stellachen
Calcite | Level 5

So sorry about that, it is my first time to do that , so may have some problems and now I changed it.

 

 

Bests

Stella

Reeza
Super User

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;

 

Stellachen
Calcite | Level 5
Thanks a lot! I understand what's you means but one question is I didn't know use what variable to calculate the frequency.
Reeza
Super User

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.

 

PaalNavestad
Pyrite | Level 9

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.

ballardw
Super User

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 9 replies
  • 1109 views
  • 3 likes
  • 5 in conversation