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 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 1355 views
  • 4 likes
  • 4 in conversation