Programming the statistical procedures from SAS

How can I separate rows and substitute the value of variables

Reply
Senior User
Posts: 1

How can I separate rows and substitute the value of variables

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!

Super User
Posts: 10,857

Re: How can I separate rows and substitute the value of variables

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.

Ask a Question
Discussion stats
  • 1 reply
  • 97 views
  • 0 likes
  • 2 in conversation