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
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.