Hello Community,
Question from a noob.
I have two variables that need to be compared. Variable x is the old variable and variable y the new one.
The values in variable x partly have a leading zero and a different date format than the values in variable y. Other values may be ok.
I created two new variables. Varnew1 holds all formatted values with a leading zero. Varnew2 holds all formatted new date values. I used tranwrd.
Is it now possible to replace the new values into Var x so that i can compare var x and var y?
Example:
Var x Var y Varnew1 Varnew2
1 1
30
05 5 5
2017-09-14 21076 21076
...
Something like this?
data have;
length Var_X Var_Y $10;
input Var_X Var_Y;
cards;
1 1
30 .
05 5
2017-09-14 21076
;run;
options datestyle=ymd;
data want;
set have;
length Varnew1 Varnew2 $10;
if Var_X ne '' and Var_Y ne '' and Var_X ne Var_Y then do;
if input(Var_Y,10.)=input(Var_X,?? anydtdte10.) then
Varnew2=Var_Y;
else if input(Var_Y,10.)=input(Var_X,10.) then
Varnew1=Var_Y;
end;
run;
I added the OPTIONS DATESTYLE=YMD because some dates, e.g. 2017-09-08 can be ambigous.
Something like this?
data have;
length Var_X Var_Y $10;
input Var_X Var_Y;
cards;
1 1
30 .
05 5
2017-09-14 21076
;run;
options datestyle=ymd;
data want;
set have;
length Varnew1 Varnew2 $10;
if Var_X ne '' and Var_Y ne '' and Var_X ne Var_Y then do;
if input(Var_Y,10.)=input(Var_X,?? anydtdte10.) then
Varnew2=Var_Y;
else if input(Var_Y,10.)=input(Var_X,10.) then
Varnew1=Var_Y;
end;
run;
I added the OPTIONS DATESTYLE=YMD because some dates, e.g. 2017-09-08 can be ambigous.
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.