Hi,
I have variable "time", example: 30OCT2019:23:46:26.83 I want to delete all the "time" when it has "OCT" in the value. I wrote: IF ((scan(time,2,'2019')) = 'OCT' THEN Delete; but it didnt work, any ideas on how to do it? Thanks!
/*if DT is Character*/
data have;
dt='30OCT2019:23:46:26.83';
output;
dt='30NOV2019:23:46:26.83';
output;
run;
data want;
set have;
where month(input(dt,date9.)) ne 10;
run;
/*if DT is numeric*/
data have;
dt='30OCT2019:23:46:26.83'dt;
output;
dt='30NOV2019:23:46:26.83'dt;
output;
format dt datetime20.;
run;
data want;
set have;
where month(datepart(dt)) ne 10;
run;
@yichentian226 Basically, you need to be aware whether your variable is numeric or character. Since you want to exclude OCT values,those are 10th month of the year. You can use an informat in case your variable is char to get the appropriate numeric SAS date and filter. In case your datetime values are numeric, you extract the datepart and then filter with the same condition -->not equal to 10th month
/*if DT is Character*/
data have;
dt='30OCT2019:23:46:26.83';
output;
dt='30NOV2019:23:46:26.83';
output;
run;
data want;
set have;
where month(input(dt,date9.)) ne 10;
run;
/*if DT is numeric*/
data have;
dt='30OCT2019:23:46:26.83'dt;
output;
dt='30NOV2019:23:46:26.83'dt;
output;
format dt datetime20.;
run;
data want;
set have;
where month(datepart(dt)) ne 10;
run;
@yichentian226 Basically, you need to be aware whether your variable is numeric or character. Since you want to exclude OCT values,those are 10th month of the year. You can use an informat in case your variable is char to get the appropriate numeric SAS date and filter. In case your datetime values are numeric, you extract the datepart and then filter with the same condition -->not equal to 10th month
You need to show us what type of variable that is. It may be a datetime variable, numeric with a format assigned like datetime21.2. In which case "OCT" is not part of the value. Run Proc Contents on your data set to confirm variable type and any associated format.
If that is the case then the code would be something like:
If month(datepart(time))= 10 then delete.
Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.
Register today!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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: