BookmarkSubscribeRSS Feed
My_SAS
Calcite | Level 5

I am havig a variable like this 

no

1

2

3

4

5

I want to create a new varible to move uprow up..

no New_no

1  2

2  3

3  4

4  5

5  .

3 REPLIES 3
art297
Opal | Level 21

here is one way:

data have;

  input no;

  cards;

1

2

3

4

5

;

data want;

  set have end=lastone;

  set have ( firstobs = 2 keep = No rename = (No = New_No) )

      have (      obs = 1 drop = _all_                     );

New_No = ifn(  lastone, (.), New_No );

run;

MikeZdeb
Rhodochrosite | Level 12

Hi ... another approach ...

data want;

merge have have (firstobs=2 rename=(no=new_no));

run;

PeterPanPan
Calcite | Level 5

If the data set contains only these two variables, I would do it like this:

*step 1. Delete the first row;

data output1;

set input;

if first.no then delete;

rename no=new_no;

run;

*step 2. Build new variable;

data output2;

set ouput1;

no=lag(new_no);

run;

Then deal with the first obs of no and last obs of new_no.

HTH!

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 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
  • 8517 views
  • 1 like
  • 4 in conversation