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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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