DATA Step, Macro, Functions and more

comparision between 2 variables are not matching

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

comparision between 2 variables are not matching

HI,

 

I am trying a simple step to see if both variables do not match then falg it but i can see both variables the same and have a flag.

Attached test data and code used

 

data nd;
   set test;
   format _all_;
   informat _all_;
run;

data ing;
   set nd;
   if start_time ne time2 then flag=1;
run;
Attachment

Accepted Solutions
Solution
‎02-15-2018 09:18 AM
SAS Super FREQ
Posts: 9,259

Re: comparision between 2 variables are not matching

Posted in reply to hanskronie
A numeric variable will have a '.' for missing. Your statement is creating flag as a numeric variable
if start_time ne time2 then flag=1; (numeric flag -- all missing will be .)

But if you did:
if start_time ne time2 then flag='1'; (character variable missing would be blank)

cynthia

View solution in original post


All Replies
PROC Star
Posts: 1,190

Re: comparision between 2 variables are not matching

Posted in reply to hanskronie

Seems to work fine?

 

In what row do you see the problem?

 

data WORK.TENT;
  infile datalines dsd truncover;
  input SUBJECT:$5. START_TIME:32. TIME2:32.;
datalines4;
N1001,47460,47460
N1001,47460,47460
N1001,45480,45240
N1001,45480,45240
N1002,44880,44880
N1002,44880,44880
N1002,35700,35700
N1002,35700,35700
N1003,54300,54300
N1003,54300,54300
N1008,0,41880
N1008,0,41880
N1008,47400,47400
N1008,47400,47400
N1010,33300,33300
N1010,33300,33300
N1010,33780,33780
N1010,33780,33780
N1011,33660,33660
N1011,33660,33660
N1011,33180,33180
N1011,33180,44760
N1013,31920,31920
N1013,31920,31920
N1013,29760,29760
N1013,29760,29760
N1017,41700,41700
N1017,41700,41700
N1017,42600,42600
N1017,42600,42600
N1018,59100,59100
N1018,59100,59100
N1018,54900,54900
N1018,54900,54900
N1020,49500,49500
N1020,49500,49500
N1020,53400,53400
N1020,53400,53400
N1022,37920,37920
N1022,37920,37920
N1022,46380,46380
N1022,46380,46380
N1024,49200,49200
N1024,49200,49200
N1024,47700,49500
N1024,47700,49500
N1025,51000,51000
N1025,51000,51000
N1026,48480,48480
N1026,48480,48480
;;;;

data nd;
   set TENT;
   format _all_;
   informat _all_;
run;

data ing;
   set nd;
   if start_time ne time2 then flag=1;
run;
New Contributor
Posts: 3

Re: comparision between 2 variables are not matching

I get for a lot of them for example first 2 rows it flags as 1 where as it should be blank.

 

PROC Star
Posts: 1,190

Re: comparision between 2 variables are not matching

Posted in reply to hanskronie

Running

 

proc print data=ing(obs=2);
run;

on the exact code that I posted gives

Capture.PNG

 

 

 

 

 

 

 

 

 

 

as desired?

Solution
‎02-15-2018 09:18 AM
SAS Super FREQ
Posts: 9,259

Re: comparision between 2 variables are not matching

Posted in reply to hanskronie
A numeric variable will have a '.' for missing. Your statement is creating flag as a numeric variable
if start_time ne time2 then flag=1; (numeric flag -- all missing will be .)

But if you did:
if start_time ne time2 then flag='1'; (character variable missing would be blank)

cynthia
☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 81 views
  • 0 likes
  • 3 in conversation