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

For a dataset like the following one:

data example;
input interval zzz;
cards;
99 .345
100 -.398
101 .546
102 .968
103 -.012
104 .489
105 .005;
run;

how can I create 1 lead in variable zzz? I have found people recommending about PROC EXPAND, but I could not work that out. Would you please help?

 

Thank you.

 

Regards.

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

People recommending proc expand were right, as long as you have SAS/ETS licenced

 

proc expand data=example out=want;
id interval;
convert zzz=zzz_lead / transformout=(lead 1);
run;
PG

View solution in original post

4 REPLIES 4
Astounding
PROC Star

So what should the results look like?  Does the final observation get deleted?

Tom
Super User Tom
Super User

Not sure if there is a BEST way. Here is an easy way.  I assume you meant to include that last line of data in your example?

data example;
input interval zzz;
cards;
99 .345
100 -.398
101 .546
102 .968
103 -.012
104 .489
105 .005
;

data want ;
  set example;
  set example(firstobs=2 keep=zzz rename=(zzz=zzz_lead1)) example(obs=1 drop=_all_);
run;
                              zzz_
Obs    interval      zzz      lead1

 1         99       0.345    -0.398
 2        100      -0.398     0.546
 3        101       0.546     0.968
 4        102       0.968    -0.012
 5        103      -0.012     0.489
 6        104       0.489     0.005
 7        105       0.005      .
PGStats
Opal | Level 21

People recommending proc expand were right, as long as you have SAS/ETS licenced

 

proc expand data=example out=want;
id interval;
convert zzz=zzz_lead / transformout=(lead 1);
run;
PG
d6k5d3
Pyrite | Level 9
Awesome! Worked fine!

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 4 replies
  • 797 views
  • 7 likes
  • 4 in conversation