BookmarkSubscribeRSS Feed
jiznow
Calcite | Level 5

Hi all,

 

I am facing a problem of separating a single row into multiple rows. My original data is as following:

student id | year_code

----------------------------

1111 | 1213

----------------------------

1111 | 1314

----------------------------

1112 | 1213

......

I want to change 1213 into 201280,201310 and 201350, i.e, change the first row 1111|1213 to

1111 |201280

-----------------

1111 |201310

-----------------

1111 |201350.

 

Is there any code I can use to obtain the result I want?

 

Thank you!

1 REPLY 1
ballardw
Super User

Does anything get done to the year_code values of 1314 and or 1213 in the third row?

From what you post it isn't even clear if you have any SAS data set, do you?

 

If you have a SAS data set and want to change only the first observation something like;

 

Data want;

   set have;

   if _n_=1 then do;  /*<= this does the first row only*/

      year_code=201280;

      output; /* replace the value and then save to output*/

      year_code=201310;

      output; /* second value and then save to output*/

      year_code=2013500;

      output; /* third value and then save to output*/

  end; /* the block of statements for the first record*/

  else output; /* write other records unchanged*/

run;

 

 

If there is supposed to be some logic in how other values may be assigned you should state it.

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 ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 1 reply
  • 1123 views
  • 0 likes
  • 2 in conversation