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.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.