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.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.