Hello all,
I would be happy to get your guidance in the following query.
I have two data sets- Data1 and Data2 and I need Dataset called data3 as shown below
Data1- Looks like Data2-Looks like Data3- Output required
Var1 (Num) Var2 (Char) (it is blank) Var1 (Num) Var2 (Char) Var1 (Num) Var2 (Char)
1 Blank 1 green 1 green
1 Blank 2 Red 1 green
1 3 Orange 1 green
2 4 White 2 Red
2 2 Red
2 .
2
2 .
3 3 Orange and for 4 White and so on.
3
3
3 I used the following- after sorting-----data data3; merge data1 (in=a) data2 (in=b); by var1; if a; run;
3
4
4
4
4
4
4
Please guide me
Thank you
Problem is the existence of VAR2 on your 'many' table. Since it reads only one record from the 'few' table only the first value will be replaced. Easiest solution is to DROP or RENAME the variable.
data data3;
merge data1 (in=in1 drop=var2) data2 (in=in2);
by var1;
if in1;
run;
Problem is the existence of VAR2 on your 'many' table. Since it reads only one record from the 'few' table only the first value will be replaced. Easiest solution is to DROP or RENAME the variable.
data data3;
merge data1 (in=in1 drop=var2) data2 (in=in2);
by var1;
if in1;
run;
Thank you Tom, I thought the same thinkg but could not do it. thanks.
Thank you so much Torres.
Try this:
Data Data1;
INPUT VAR1;
VAR2=' ';
cards;
1
1
1
2
2
2
2
2
3
3
3
3
3
4
4
4
4
4
4
;
RUN;
DATA Data2;
LENGTH VAR1 8 VAR2 $ 8;
INPUT VAR1 VAR2;
CARDS;
1 green
2 Red
3 Orange
4 White
;
RUN;
data data3;
merge data1 (keep=var1) data2;
by var1;
run;
Regards,
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.