BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
yichentian226
Obsidian | Level 7

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!

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
/*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  

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
/*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  

ballardw
Super User

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.

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

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!

Register now

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 878 views
  • 0 likes
  • 3 in conversation