hi I have two variables A and B . I wanted to compare those two variables based on date variable. on a particular date like 02/02/2019 if data is same then copy data before 02/0/2/2019 from A and 02/02/2/019 onwards data from B and create new variable.
I am trying something like this.
data test;
set test_1;
length new_variable 8.;
if date='02FEB2019' then do;
if A=B then new_variable = A;
end;
run;
I think what you want to do is something like this:
data test;
set test_1;
retain switch 0;
if date='02FEB2019' and A=B then
switch=1;
if switch then
C=B;
else
C=A;
run;
Try this
if date='02FEB2019'D then do;
IIf that doesn' t fix the problem, then please explain the problem in a lot more detail, and please show us a portion of your data set.
it bring data for that date but I wanted to bring all the data from this date. but it gives me only for that particular day record like one record.
29
30 data test
31 set test_1
32 length C 8.
33
34 if date='31APR2002'd then do
35 if A =B then C=A
36 end
run
so like following if A and b have same data on 30/04/2002 then before 30/04/2002 data comes from A and after 30/
date A B
28-Feb-02 1236 5842
31-Mar-02 5662 553
30-Apr-02 3526 3526
30-Jun-02 3525 2060
30-Sep-02 3524 2041
31-Dec-02 3523 2022
31-Mar-03 3522 2003
30-Jun-03 3521 1984
30-Sep-03 3520 1965
31-Dec-03 3519 1946
and after 30/04/2002 comes from B and create variable C. sorry it didn't allow me to finish whole question in one
Please do NOT post code or log without semicolons. We have previously requested you not do this. Use the </> icon to post your log and use the "running man" icon to post code.
In your example, what should be done if A is not equal to B on the given date?
sorry I didn't add semicolons as it gives me error when write message here. if A=B then variable C should be created else c will be null. the way C should be created is before 30April2002 should come from A and after 30April2002 from B. thanks For helping
I think what you want to do is something like this:
data test;
set test_1;
retain switch 0;
if date='02FEB2019' and A=B then
switch=1;
if switch then
C=B;
else
C=A;
run;
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
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.