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
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);
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);
Please try
data want;
merge have have(firstobs=2 keep=columna rename=(columna=last)) ;
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.