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: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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