BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Tegan
Calcite | Level 5

I have a dataset ("Dataset1") with a date column ("Date").  The format is mm/dd/yyyy.

I want to make multiple data files with the information from the rows split up by year.

So it would go from Dataset1 to datasets "1999" and "1998" etc.

Can someone help me with the code?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Why do you want to split up your datasets? This is a commonly asked question, the answer is usually don't do it. 

The manual example, that assumes that your date variable is a SAS numeric variable with a date format, not a character variable:

data Y1998 Y1999;

set have;

if year(date) = 1998 then output Y1998;

else if year(date) = 1999 then output Y1999;

run;

View solution in original post

3 REPLIES 3
Reeza
Super User

Why do you want to split up your datasets? This is a commonly asked question, the answer is usually don't do it. 

The manual example, that assumes that your date variable is a SAS numeric variable with a date format, not a character variable:

data Y1998 Y1999;

set have;

if year(date) = 1998 then output Y1998;

else if year(date) = 1999 then output Y1999;

run;

Tegan
Calcite | Level 5

I have millions of records spread over 25 datasets which are all by year.  So I have 25 yearly datasets containing variables A-Y 1999, A-Y 2000, A-Y 2001...And I have one dataset for Variable Z 1999-2001.  I need to split the Variable Z dataset up by year so I can remerge it with Variables A-Y to make A-Z variables for each year in one dataset.

Does that make sense?

The dataset which has one key and 25 years worth of data was uploaded from a text file.  It was a vertical bar delimited file which was just Key (123), Date (01/01/2001), etc. etc...So it didn't specify a format, I think SAS just reads it as a character string, right?

data Y1998 Y1999; --> This creates output datasets?

set have; -->I don't know what a set statement is

if year(date) = 1998 then output Y1998; -->So if the variable name is "datevariable" then it would be "if year(datevariable) = 1998 then output Y1998;"?

else if year(date) = 1999 then output Y1999; -->And I just add as many of these statements as there are years?

run;

Reeza
Super User

Why not merge it directly? 1 million records isn't that big of a dataset.

 

If you're not familiar with SAS at all, you may want to view these videos/tutorials. Or are you using SAS Enterprise Guide?

SAS Starter Kit

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 2203 views
  • 0 likes
  • 2 in conversation