Hi All,
I am trying to create a column that will have the entries that combines two other columns. For example I want to create column C where value will include from Column A and Column B such that:
Column A Column B Column C
-------------- ----------------- -----------------
12 Kilometers A1001 A1001-X3
6 Kilometers A1001 A1001-X2
3 Kilometer A1001 A1001-X1
12 Kilometers A1002 A1002-X3
6 Kilometers A1002 A1002-X2
3 Kilometers A1002 A1002-X1
12 Kilometers A1003 A1003-X3
6 Kilometers A1003 A1003-X2
3 Kilometers A1003 A1003-X1
and so on and so on and so on
and so on and so on and so on
For the first three, I made SAS code as,
data x; set y;
if column A= '12 Kilometers' and column B= 'A1001' then Column C= 'A1001-X3';
if column B= '6 Kilometers' and column B= 'A1001' then Column C= 'A1001-X2';
if column A= '3 Kilometers' and column B= 'A1001' then Column C = 'A1001-X1';
run;
My question is:
How do I all create similar values in Column C for the rest of the numbers (i.e. A1002, A1003, A1004, A1005....) in one or two steps without having to
write code for each and every number? If there is a simple, 1-2 generic steps that take care of the all the numbers that I want to put in column C?
Thanks in advance.
Sapkota
if column A= '12 Kilometers' and column B= 'A1001' then Column C= cats(ColumnB, '-X3');
else if column B= '6 Kilometers' and column B= 'A1001' then Column C= cats(ColumnB, '-X2');
else if column A= '3 Kilometers' and column B= 'A1001' then Column C = cats(ColumnB, '-X1');
Thank you much.
You could just create and apply a format. E.g.:
proc format;
value $colc
'12 Kilometers'='X3'
'6 Kilometers'='X2'
'3 Kilometers'='X1'
;
run;
data want;
set have;
ColumnC=catx('-',ColumnB,put(ColumnA,$colc.));
run;
Thanks Arthur,
Your advise worked for me. I got my answer!
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.