BookmarkSubscribeRSS Feed
Moviefan04
Calcite | Level 5

I am working in SAS 9.4.  I have a data set and one of the variables is called 'state'.  I need to remove all rows in which the 'state' variable is not equal to 'Alaska'.  I also need to combine three other variables (month, day, and year) to create a new variable called EruptionDate and then drop those other 3 variables.  The final thing that I can't figure out is how to only display the eruptions occuring after the year 2005.  I am quite new to SAS and programming in general and this is what I have so far, but it's not working:

 

DATA Alsaka;

 SET Work.earthquake;

IF State = Alaska

 THEN EruptionDate = Month, Day, Year

 ELSE REMOVE row;

DROP Month;

DROP Day;

DROP Year;

 

RUN;

 

PROC PRINT Data= Alaska;

 WHERE year GT 2005;

 

RUN;

 

 

Thanks for any help.

 

3 REPLIES 3
GreggB
Pyrite | Level 9

There are errors in your code. Can you post a few observations of your data?

art297
Opal | Level 21

Depends upon what values you have for Month, Day and Year. You may be able to use something like:

DATA Alaska (drop=Month Day Year);
  SET Work.earthquake;
  format EruptionDate date9.;
  IF State = 'Alaska' THEN do;
    EruptionDate = mdy(Month, Day, Year);
    output;
  end;
RUN;
PROC PRINT Data= Alaska;
 WHERE year(EruptionDate) GT 2005;
RUN;

Art, CEO, AnalystFinder.com

 

Moviefan04
Calcite | Level 5

I made a few adjustments to tailor it to get my desired result but your post helped a lot.  Thank you!

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
  • 3 replies
  • 876 views
  • 1 like
  • 3 in conversation