Hi i am stuck with basic prob.
I have two datasets Data1 having variables a, b, c, d like
a b c d
2 3 5 6
1 0 1 4
0 1 4 5
2 4 3 1
and Data2 having variables ch and lm
ch lm
p 3
q 5
l 7
m 4
I Need my output having variables ch (Data2), (a,b,c,d) from Data1 and a new variable "label" having "1" if any of the value in the row of data1 is >= 5.
my output data will have variables "ch", "a"," b", "c", "d", "label".
Thanks
I don't have a sound understanding of your req nor your data. Is this what you want?
data want;
merge data2(drop=lm) data1;
if max(a,b,c,d)>=5 then label=1;
run;
I don't have a sound understanding of your req nor your data. Is this what you want?
data want;
merge data2(drop=lm) data1;
if max(a,b,c,d)>=5 then label=1;
run;
Sir Thanks for your quick response,
Actually, It was a toy example.
Can you generalize if i have too many variables in Data1. So, i can't put them manually.
Thanks
You could use a variable list using -- (Double dash)
so for example: max(of a--d);
Given that:
You would be better off creating the new variable first, and combining the data sets later. For example:
data data1_new;
set data1;
label = (max(of _numeric_) >= 5);
run;
Then do combine them, you can use either SET or MERGE. It depends on what you want the result to be if there are different numbers of observations in DATA1 and DATA2. Here is one possibility to consider:
data want;
set data1_new;
set data2 (drop=lm);
run;
Thanks Austonding.. yours code is also working
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 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.