I'm trying to use an IF statement to check and see if the value I want is in the date format MMDDYY8. and if so do.....
Data:
ENG-112 ENGLISH COMPOSITION II..... 06/30/03 CR | 1.5 *TE | |
ENG-113 ENGLISH COMPOSITION III.... 06/30/03 CR | 1.5 *TE | |
IF statement:
IF index(row, '-')= 14 and ANYDIGIT(row)= 15 and substr(row,findc(row, '/')-2,8)= "MMDDYY8.d" then
do
....
end;
I guess you could hard code it:
data work.have;
length row $100.;
input @1 row $Char69.;
if substr(row,14,1)='-' and input(substr(row,47,8),mmddyy8.) ne . ;
cards;
ENG-112 ENGLISH COMPOSITION II..... 06/30/03 CR 1.5 *TE
ENG-113 ENGLISH COMPOSITION III.... 06/30/03 CR 1.5 *TE
;
run;
Is your data one long string or are you trying to figure out how to parse it? I would parse it as text and then deal with it separately, you can try anydtdte format as well as an informat.
It is one long string. I plan on parsing it but i need the IF statement to check and make sure I want the values.
You may want something like:
pos = prxmatch('/\d{2}\/\d{2}\/\d{2} /',x);
X is the name of the variable to search the string.
Pos here is the position that a dd\dd\dd<space> string is found in X
You need to have the final space as otherwise dd\dd\dddd would not be differentiated.
I guess you could hard code it:
data work.have;
length row $100.;
input @1 row $Char69.;
if substr(row,14,1)='-' and input(substr(row,47,8),mmddyy8.) ne . ;
cards;
ENG-112 ENGLISH COMPOSITION II..... 06/30/03 CR 1.5 *TE
ENG-113 ENGLISH COMPOSITION III.... 06/30/03 CR 1.5 *TE
;
run;
To avoid getting messages about invalid data, you might want to replace this:
,mmddyy8.)
with this:
,??mmddyy8.)
Test this version with a line of data containing 06/10/2003 and see what happens. This was my first approach to the logic.
It will treat it as a valid date of 6/10/1920 (assuming your year cutoff date is the same as my default).
If you never have mm/dd/yyyy data no problem.
Also, if the date is invalid such as 02/30/03 it will also be missing. So you may need to check further.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.