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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.