I have a variable Enrollment_month - type character, length 8 with value ex:FEB2022. I want to convert this into date format as 20220201. Please help
data Want;
Enrollment_month = 'FEB2022';
Enrollment_date = input('01' !! Enrollment_month, date9.);
format Enrollment_date yymmddn8.;
put _all_;
run;
Since your notation fits most of the DATE9 informat, conversion is easy:
data want;
set have (rename=(enrollment_month=_em));
format enrollment_month yymmddn8.;
enrollment_month = input(cats("01",_em),date9.);
drop _em;
run;
PS I changed your subject line. "Hi" is not descriptive and only makes you look silly.
data Want;
Enrollment_month = 'FEB2022';
Enrollment_date = input('01' !! Enrollment_month, date9.);
format Enrollment_date yymmddn8.;
put _all_;
run;
If it is already a SAS date value, you only need to change the assigned format, e.g. with PROC DATASETS for the dataset, or with a FORMAT statement (or FORMAT= option in PROC SQL) wherever needed.
"If enrollment_month is type date with same value" - A numeric variable can't contain the same value as "FEB2022" as that is character data. The closest you can get is this, where you define it as a date based on 01 Feb 2022:
data Want;
Enrollment_month = '01FEB2022'd;
Enrollment_date = Enrollment_month;
format Enrollment_month date9. Enrollment_date yymmddn8.;
put _all_;
run;
PS there is no type "date" in SAS. SAS has only two types of variables, character and numeric.
Dates are stored in numeric variables, as counts of days with 1960-01-01 as day zero, and with a proper format assigned to make the raw value human-readable.
Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.
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.