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