hello, i have data set like this
DATETX | TRMT1 | TRMT2 |
1/3/2019 | 0 | 0 |
1/7/2019 | 0 | 0 |
01/22/2019 | 1 | 0 |
02/15/2019 | 0 | 1 |
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.
DATETX | TRMT1 | TRMT2 |
1/3/2019 | 0 | 0 |
1/7/2019 | 0 | 0 |
01/22/2019 | 1 | 0 |
02/15/2019 | 0 | 1 |
please help.
" 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;
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.
Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!
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.