BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

hello, i have data set like this

DATETXTRMT1TRMT2
1/3/201900
1/7/201900
01/22/201910
02/15/201901

 i would like to remove observation that has date but both trmt1 and trmt2 have 0 value.

i used this code:

data janfebs.JAN2FEB2019_MERGED_T_1;
set janfebs.JAN2FEB2019_MERGED_T;
if datetx NE . and TRMT1 and TRMT2="00" then delete;
run;

but it did not work. the log says 


NOTE: Character values have been converted to numeric values at the places given by:
(Line):(Column).
436:20
NOTE: There were 702 observations read from the data set JANFEBS.JAN2FEB2019_MERGED_T.
NOTE: The data set JANFEBS.JAN2FEB2019_MERGED_T_1 has 691 observations and 256 variables.
NOTE: DATA statement used (Total process time):
real time 0.11 seconds
cpu time 0.01 seconds

i originally had 702 observations.

and the result shows same as before observation with 0 values are not removed.

DATETXTRMT1TRMT2
1/3/201900
1/7/201900
01/22/201910
02/15/201901

please help.

2 REPLIES 2
novinosrin
Tourmaline | Level 20

" i would like to remove observation that has date but both trmt1 and trmt2 have 0 value."

 

 

data want;

set have;

if sum(trmt1,trmt2)>0;

run;

 

To include Datetx in your condition

if datetx >. and sum(trmt1,trmt2)>0;
Shmuel
Garnet | Level 18

The condition and TRMT1 and TRMT2="00" means: ... and TRMT1=1 and TRMT2="00" 

which I believe you didn't mean to.

You want to remove observation that has date but both trmt1 and trmt2 have 0 value,

so the correct code is:

if datetx NE . and TRMT1=0  and TRMT2=0 then delete;

Pay attention to the note in the log:

NOTE: Character values have been converted to numeric values 

you did not post the whole log. I suppose the the "00" were converted to 0, assuming TRMT1 and TRMT2, both are numeric.

 

 

    

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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