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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
Cynthia_sas
SAS Super FREQ
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

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

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;
hanskronie
Calcite | Level 5

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

 

PeterClemmensen
Tourmaline | Level 20

Running

 

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

on the exact code that I posted gives

Capture.PNG

 

 

 

 

 

 

 

 

 

 

as desired?

Cynthia_sas
SAS Super FREQ
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

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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
  • 4 replies
  • 821 views
  • 0 likes
  • 3 in conversation