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

Hello I have the following data:

DATA HAVE;
enfile cards turnover;
input columnA $ columnB $ columnC $;
datalines;
AAAA aaaa hello1
BBBB bbbb hello2
CCCC cccc hello3
DDDD dddd hello4
EEEE eeee hello5
;
RUN;

I want to add a column representing the leading ColumnA;

And have something like:

 

DATA WANT;
enfile cards turnover;
input columnA $ columnB $ columnC $ leadingcolumnA $;
datalines;
AAAA aaaa hello1 BBBB
BBBB bbbb hello2 CCCC
CCCC cccc hello3 DDDD
DDDD dddd hello4 EEEE
EEEE eeee hello5 
;
RUN;

When I do 

DATA want;
merge have have(firstobs=2 Rename=columnA=LeadingColumnA);
run;

It shifted the ColumnB and ColumnC as well, which is not what I want.

Do you have any Idea how to do that ?

 

Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

Hi @Hugo_B  you missed keep=columnA. So without that, you are allowing B,C to be overwritten.

 

merge have have(firstobs=2 Rename=columnA=LeadingColumnA keep=columnA);

 

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20

Hi @Hugo_B  you missed keep=columnA. So without that, you are allowing B,C to be overwritten.

 

merge have have(firstobs=2 Rename=columnA=LeadingColumnA keep=columnA);

 

Jagadishkatam
Amethyst | Level 16

Please try

 

data want;
merge have have(firstobs=2 keep=columna rename=(columna=last)) ;
run;
Thanks,
Jag

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
  • 2 replies
  • 609 views
  • 1 like
  • 3 in conversation