BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
drfzLee
Calcite | Level 5

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

...

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
s_lassen
Meteorite | Level 14

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.

 

View solution in original post

1 REPLY 1
s_lassen
Meteorite | Level 14

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.

 

Ready to join fellow brilliant minds for the SAS Hackathon?

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!
How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 361 views
  • 0 likes
  • 2 in conversation