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

good day,

 

here is my program,

 


data have;
input name $40.;
infile datalines dlm=',';
datalines;
A
AAAOTAXIUNION
AACARPETSDELHI
AADESIGNFURNZTURNSAMUTPRAKAN
AADRIVERTRAININGLTAUCKLAND
AAFOOTWEARCENTRALWORBANGKOK
AAFOOTWEARGAYSORNBANGKOK
AAFOOTWEAROUTLETAYUTTAYUTTHAYA
AAHONGKONG
AAMCLENNANGKMPOKOLBIN
;
run;

data have2;
set have;
lag_name=lag(name);

run;

 

i also want to add a lead Row here for comparison. can anyone help? 

 

thanks in advance

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have2;
    merge have
          have(firstobs=2 rename=(name=lead_name) keep=name);
    lag_name=lag(name);
run;

View solution in original post

7 REPLIES 7
PeterClemmensen
Tourmaline | Level 20

Try this

 

data have2;
    merge have
          have(firstobs=2 rename=(name=lead_name) keep=name);
    lag_name=lag(name);
run;
harrylui
Obsidian | Level 7
NOTE: Writing TAGSETS.SASREPORT13(EGSR) Body file: EGSR
31
32 GOPTIONS ACCESSIBLE;
33
34 data have2;
35 merge have
36 have(firstobs=2 rename=(name=lead_name) keep=name);
37 lag_name=lag(name);
38 run;

ERROR: No BY statement was specified for a MERGE statement.


not work
ed_sas_member
Meteorite | Level 14

HI @harrylui 

 

Could you try the same code with the following option before:

Options mergeNoBy=noWarn ;
harrylui
Obsidian | Level 7
thank you!
PeterClemmensen
Tourmaline | Level 20

Please check that the MERGENOBY System Option is set to NOWARN.

harrylui
Obsidian | Level 7
thank you! my problem is fixed!
Krueger
Pyrite | Level 9
I always just reverse sort order and do lag(), this is WAY easier!

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

Register now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

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