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

Hello!

 

I have a list of 246 schools. I am trying to add a year column but each school should have 2019, 2018, 2017, 2016, and 2015. Can someone help me figure out a way to code this so that I do not have to go in manually for this?

 

Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

If your current data has one record per school then something like this:

 

data want;
   set have;
   do year=2015 to 2019;
       output;
   end;
run;

which will duplicate all the values in the other variables.

If you do not have one record per school then example of what you currently have and what the output should look like.

 

If the actual order really matters you could do: year = 2019 to 2015 by -1

 

View solution in original post

2 REPLIES 2
ballardw
Super User

If your current data has one record per school then something like this:

 

data want;
   set have;
   do year=2015 to 2019;
       output;
   end;
run;

which will duplicate all the values in the other variables.

If you do not have one record per school then example of what you currently have and what the output should look like.

 

If the actual order really matters you could do: year = 2019 to 2015 by -1

 

Reeza
Super User
Do you want 4 columns, one for each year per school?
Or do you want 4 rows, one for each year per school?
Or do you already have years but not all school has every year?

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 603 views
  • 1 like
  • 3 in conversation