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;
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!
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.